Reputation: 17193
These are the two tables.
tbl_Invoice
tbl_Payment
What I want is Pending Invoices
by a particular Client.
Existing Query is as below:
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
But it gives blank result becuase the Payment table is blank.
Upvotes: 3
Views: 1681
Reputation: 37354
You need to move condition from WHERE
to 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
Upvotes: 9