Using two LEFT JOIN
s i.e.
SELECT <some columns>
FROM Table1 AS t1
LEFT JOIN Table2 AS t2 ON <condition1>
LEFT JOIN Table2 AS t3 ON <condition2>
is this same as using AND
in single LEFT JOIN
? i.e.
SELECT <some columns>
FROM Table1 AS t1
LEFT JOIN Table2 AS t2 ON <condition1>
AND <condition2>
Both are same or different(in general)?
Best Answer
They are different. In the first option you get 2 times
Table2
into your query. Once ast2
and once ast3
. Both have a different content and you must put them somehow back together. To me this is more an OR instead of an AND. In the second option you get only theTable2
rows that meet both criteria.Suppose you have
Table2
with the following content:Suppose you want to have the rows that are
Blue
andS
. In your first option you get all rows (t2
for example with allBlue
andt3
with allS
) and in your second option you only get row 2.