私は2つのテーブルを持っています:
- お客様
- 顧客通信
customer テーブルには固有のsequence
列があり、customer_communication テーブルには customer テーブルcustomer_seq
のシーケンス列と一致する列があります。
customer_communication テーブルの行には datetime 列があり、これらのクエリを使用して両方のテーブルからデータを選択しています:
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 = sequence であり、datetime 列から 15 日経過している行を選択します。
customer_communication テーブルに存在しない顧客テーブルのすべての行を表示する方法
たとえば、customer にシーケンス 1 があり、これは customer_communication テーブルの customer_seq 列に存在しないので、これを表示したい