I'm looking to join three tables under a condition. Table1 is the "main" table that has the related id's to the other two tables.
I know how to make a single join:
SELECT name, column2
FROM table1
LEFT OUTER JOIN table2 ON table1.id2 = table2.id2
However I am unable to connect it with a second JOIN to obtain column3
using table1.id3 = table3.id3
.
There is an additional difficulty as I only want to display those records where name = $name
(a predefined variable).
table1
id | id2 | id3 | name
table2
id2 | column2
table3
id3 | column3
Any tips on how to connect the three statements are greatly appreciated.
Edit:
SELECT name, column2, column3 FROM table1
LEFT OUTER JOIN table2 ON table1.id2 = table2.id2
LEFT OUTER JOIN table3 ON table1.id3 = table3.id3
I've managed to join the three tables and my only issue is adding the name=$name
condition.
I've tried
SELECT name, column2, column3
FROM table1
WHERE name=$name
LEFT OUTER JOIN table2 ON table1.id2 = table2.id2
LEFT OUTER JOIN table3 ON table1.id3 = table3.id3
and
SELECT name, column2, column3
FROM table1
LEFT OUTER JOIN table2 ON table1.id2 = table2.id2
LEFT OUTER JOIN table3 ON table1.id3 = table3.id3
WHERE name=$name
so far.