SELECT *
FROM TAB1
LEFT JOIN TAB2 ON TAB2.ID_TAB1 = TAB1.ID
JOIN TAB3 ON TAB3.ID = TAB2.ID_TAB3;
and
SELECT *
FROM TAB1
LEFT JOIN (SELECT *
FROM TAB2
JOIN TAB3 ON TAB3.ID = TAB2.ID_TAB3) T
ON T.ID_TAB1 = TAB1.ID;
No, they are different - the inner join to TAB3 (after the left join to TAB2) in the first query effectively turns the left join back into an inner join.
The brackets in the second query ensure that the inner join to TAB3 is evaluated before the left join - so it remains a left join to TAB2, returning only those TAB2 records where there is a corresponding TAB3 record (otherwise, the TAB1 records are returned with corresponding NULLs).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With