I don't know how to explain it. But I am trying to join two select statements/queries. I need to include customer and supplier name in the same table.
Table 1 - j:
Job ID, Customer ID
Table 2 - jl:
Job_Line.Job_ID, Supplier_ID
Table 3 - p:
ID, Name
First Select statement - customer name:
Select name
From p
INNER JOIN j ON p.id = j.customer_id
Second Select statement - supplier name:
Select name
From p
INNER JOIN jl ON p.id = jl.supplier_id
Don't know how to join above two selects, so i could have a table like:
id, customer name, supplier name
I am new to SQL and learning online. I understand the basis, but getting stuck at this finding this complex!
This should do the trick
SELECT j.id, pc.name, ps.name
FROM j
INNER JOIN p pc ON j.customer_id = pc.id
INNER JOIN jl ON j.id = jl.job_id
INNER JOIN p ps ON jl.supplier_id = ps.id
Note, pc and ps are table aliases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With