选择2表(数据库)中的实体

时间:2015-06-29 23:08:43

标签: php mysql database

这是我的mysql_query

$rs = mysql_query("SELECT calendar.datefield AS dateRow, po.po_no,cus_name,net FROM payments
                   RIGHT JOIN po ON payments.po_id=po.po_id
                   RIGHT JOIN calendar ON (DATE(po.po_date) = calendar.datefield)
                   WHERE calendar.datefield BETWEEN '$sDateFrom' AND '$sDateTo'
                  ") or die(mysql_error());// AND payments.pay_status='Paid'
?>

我想从另一个表中选择另一个实体

prod_desc FROM del_details

如何使用相同的格式查询?

常用键是po_id

1 个答案:

答案 0 :(得分:0)

根据您的需要添加LEFT / RIGHT加入..

$rs = mysql_query("SELECT calendar.datefield AS dateRow, po.po_no,cus_name,net, del_details.prod_desc 
                   FROM payments
                   RIGHT JOIN po ON payments.po_id=po.po_id
                   RIGHT JOIN calendar ON (DATE(po.po_date) = calendar.datefield)
                   JOIN del_details ON payments.po_id=po.po_id
                   WHERE calendar.datefield BETWEEN '$sDateFrom' AND '$sDateTo'
                  ") or die(mysql_error());// AND payments.pay_status='Paid'