I have 3 tables A, B and T
T holds a foreign key to table A and B respectively.
Now I would like to get all rows of (A,B,T) even if T is empty.
SELECT * from
A
LEFT OUTER JOIN T t1 ON t1.A_ID = A.id,
B
LEFT OUTER JOIN T t2 ON t2.B_ID = B.id
WHERE A.B_ID = B.ID
Now the problem is that I get too many rows so I add the following:
AND t1.id = t2.id
But now I get no rows at all which I tried to avoid in the first place via including the LEFT OUTER JOIN.
EDIT: Apart from any sample-data or table-layout my question is merely if a table T with foreign-key-dependencies to more than ONE table in this case A + B needs 2 left-outer-joins as given above or maybe there is another way?
Simply refering to table A in the second left-join like some users suggested cannot work as it is out-of-scope, also explained
here
So it works if you surround both tables with parens:
SELECT * from (A, B)
LEFT OUTER JOIN T t ON t.A_ID = A.id and t.B_ID = B.id