通过合并三个名为 luckydraw_weekone、luckydraw_weektwo 的表,在用户表中显示现有电子邮件,参与者的字段均为 Email
Posted
技术标签:
【中文标题】通过合并三个名为 luckydraw_weekone、luckydraw_weektwo 的表,在用户表中显示现有电子邮件,参与者的字段均为 Email【英文标题】:to show existing email in user table by merging three tables named luckydraw_weekone,luckydraw_weektwo, participants all thre have the fild as Email 【发布时间】:2014-01-27 21:30:27 【问题描述】:$query = "SELECT GROUP_CONCAT( luckydraw_weekone.Email),
GROUP_CONCAT(luckydraw_weektwo.Email),
GROUP_CONCAT(participants.Email)
FROM luckydraw_weekone
LEFT JOIN luckydraw_weektwo
ON luckydraw_weekone.id = luckydraw_weektwo.id
LEFT JOIN participants ON luckydraw_weekone.id = participants.id";
$qry_result = mysql_query($query) or die(mysql_error());
$display_string = "<table border=\"1\">";
$display_string = "<table border=\"1\">";
$display_string .= "<tr>";
$display_string .= "</tr>";
while($row = mysql_fetch_array($qry_result))
$display_string .= "<tr>";
$display_string .= "<td>$row[0]</td>";
$display_string .= "<td>$row[1]</td>";
$display_string .= "<td>$row[2]</td>";
$display_string .= "</tr>";
$query2 = "SELECT * FROM users WHERE mail='.$row[0].' OR mail='.$row[1].' OR mail='.$row[2].'";
$qry_result2 = mysql_query($query2) or die(mysql_error());
$display_string_user = "<table border=\"1\">";
while($row2 = mysql_fetch_array($qry_result2))
$display_string_user .= "<tr>";
$display_string_user .= "<td>$row[0]</td>";
$display_string_user .= "<td>$row[1]</td>";
// and all details you want to add
$display_string_user .= "</tr>";
$display_string .= "</table>";
$display_string_user .= "</table>";
echo $display_string;
echo $display_string_user;
【问题讨论】:
【参考方案1】:试试这个:
SELECT DISTINCT u.mail
FROM users u
INNER JOIN (SELECT email FROM luckydraw_weekone
UNION
SELECT email FROM luckydraw_weektwo
UNION
SELECT email FROM participants
) AS A ON u.mail = A.email
【讨论】:
以上是关于通过合并三个名为 luckydraw_weekone、luckydraw_weektwo 的表,在用户表中显示现有电子邮件,参与者的字段均为 Email的主要内容,如果未能解决你的问题,请参考以下文章
Arangodb AQL 连接、合并、嵌入嵌套的三个或更多集合