问题
I have a 11 tables
email1,email2,email3,email4,email5,email6,email7,email8,email9,email10,email11
and same column name Contact_Email with different email address
<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("email-db",$con);
$sql = "SELECT Contact_Email FROM email1,email2,email3,email4";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td><? echo $row['Contact_Email']; ?></td>
<td><? echo '<br>'; ?></td>
</tr>
<? } ?>
actually I want this output
select all emails from all tables using join
i want this output:
if duplicate email is in all combined table output 'yes'
else output 'no'
output like this! see
kindly help me what can I do?
回答1:
Just use UNION, following this example:
SELECT u.email
FROM email1 AS u
UNION
SELECT e.email
FROM email2 AS e
In PHP:
$sql = "SELECT u.email FROM email1 AS u UNION SELECT e.email FROM email2 AS e";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) { ...
To avoid MYSQL ERROR "Illegal mix of collations for operation 'UNION'" Please synchronize all email fields to be with equal parameters
来源:https://stackoverflow.com/questions/34016357/fatch-which-emails-are-on-the-same-lists-different-tables-but-same-column-name-e