SQL Query with join for 2 tables and create new set of columns in result with multiple foreign key in 2nd table

You can try the below – DEMO

SELECT t.id, note, t1.name as customer1, t2.name as customer2, 
t3.name as customer3
from table2 t
LEFT JOIN Table1 t1 ON t.customerId1 = t1.Id
LEFT JOIN Table1 t2 ON t.customerId2 = t2.Id
LEFT JOIN Table1 t3 ON t.customerId2 = t3.Id

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top