简体   繁体   中英

Selecting an entity in a 2 table (database)

This is my 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'
?>

and I wanted to select another entity from another table which is

prod_desc FROM del_details

How can i do it using the same format query?

common key is the po_id

Add LEFT / RIGHT join depending on your need..

$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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM