这是两张桌子。
tbl_Invoice
tbl_Payment
我想要的是Pending Invoices
特定客户。
现有查询如下:
Select * from tbl_Invoice I
left join tbl_payment P on I.client_id = P.client_id
left join tbl_client C on I.client_id = C.client_id
where I.invoice_Id not in (P.invoice_Id)
and I.client_id = 8
但它给出了空白结果,因为付款表是空白的。
答案 0 :(得分:8)
您需要将条件从WHERE
移至ON
:
Select * from tbl_Invoice I
left join tbl_payment P on (I.client_id = P.client_id
AND p.invoice_id <> I.invoice_Id)
left join tbl_client C on I.client_id = C.client_id
WHERE I.client_id = 5