【发布时间】:2013-11-13 10:18:59
【问题描述】:
我有 2 张桌子:
- 客户
- customer_communication
customer 表有一个唯一的sequence 列,customer_communication 表有customer_seq,它与 customer 表中的序列列匹配。
customer_communication 表中的行有一个日期时间列,我正在使用这些查询从两个表中选择数据:
echo '<table width="100%" border="0" cellspacing="10" cellpadding="10">';
//select from the customer_communication table
$sql="SELECT * from customer where company_status = '' and no_communication = '' order by company ASC ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs))
{
$sql2="SELECT * from customer_communication WHERE customer_seq = '".$result["sequence"]."' and datetime > DATE_ADD(DATE(now()), INTERVAL 15 DAY) order by datetime ASC ";
$rs2=mysql_query($sql2,$conn);
if(mysql_num_rows($rs2) > 0)
{
echo '<tr>
<td><a href="customer_communication.php?seq='.$result["sequence"].'">'.$result["company"].'</a></td>
</tr>';
}
}
echo '</table>';
所以它从 customer 表中选择所有行,然后从 customer_communication 表中选择 customer_seq = 序列且距离 datetime 列 15 天的行。
如何显示客户表中不存在于 customer_communication 表中的所有行
例如,customer 中有序列 1,而 customer_communication 表的 customer_seq 列中不存在此序列,因此我想显示此
【问题讨论】: