Fatch which emails are on the same lists different tables but same column name email addressess

戏子无情 提交于 2019-12-24 15:34:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!