Reputation: 17332
I got a main SQL-Table. This table is conneted to some more tables via "linking"-tables, because there could be multiple entries in both directions.
Main: id_main, title, content
Table2: id_table2, content
LinkTable2: id_main, id_table2
Table3: id_table3, content
LinkTable3: id_main, id_table3
Now I want to get the complete data. This is my attempt to connect just one table with the main table:
SELECT *
FROM Main
INNER JOIN LinkTable2 ON LinkTable2.id_main = Main.id_main
INNER JOIN Table2 ON LinkTable2.id_table2 = Table2.id_table2
How do I connect multiple tables (with multiple results)?
Upvotes: 0
Views: 61
Reputation: 13110
Just keep going!
SELECT *
FROM Main m
JOIN LinkTable2 lt2
ON lt2.id_main = m.id_main
JOIN Table2 t2
ON t2.id_table2 = lt2.id_table2
JOIN LinkTable3 lt3
ON lt3.id_main = m.id_main
JOIN Table2 t3
ON t3.id_table3 = lt3.id_table3
Upvotes: 2