Question

I need to apply a join to 3 tables (invoice, payments, client) on the client ID; however, the join I need must include all the invoices and all the payments associated with a client ID. If we have a client that has a payment and no invoices (or the other way around) this column should also appear. I don't want duplicates in the resulting table, so if a client has both invoice and payment he should appear only once. I could use a cross join and then select distinct but is there a join that can do that directly.

Was it helpful?

Solution

Something like

Select * From T1
left join T2 On T1.ClientID = T2.ClientID
Left join T3 On T1.ClientID = T3.ClientID

should do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top