Page 1 of 1

Join 1 table on 2 different tables

Posted: Tue Sep 08, 2020 9:39 am
by mister_v
Hi,

how do I make a join of 1 table on 2 different tables with the same identifier ?

Table1 : id, other_id;
table2 : id, name
table3 : id, title

So table 1 on table2 and on table 3 with other_id to id.

Re: Join 1 table on 2 different tables

Posted: Tue Sep 08, 2020 1:43 pm
by chris
You can work with a sub-query an UNION:

Code: Select all

SELECT table1.id,union_table.name FROM table1 LEFT JOIN 
   (SELECT id,name FROM table2 UNION SELECT id,title AS name FROM table3) 
   AS union_table ON table1.other_id=union_table.id;