After reading it, this is not a duplicate of Explicit vs Implicit SQL Joins. The answer may be related (or even the same) but the question is diffe
The way I do it is:
Always put the join conditions in the ON
clause if you are doing an INNER JOIN
. So, do not add any WHERE conditions to the ON clause, put them in the WHERE
clause.
If you are doing a LEFT JOIN
, add any WHERE conditions to the ON
clause for the table in the right side of the join. This is a must, because adding a WHERE clause that references the right side of the join will convert the join to an INNER JOIN.
The exception is when you are looking for the records that are not in a particular table. You would add the reference to a unique identifier (that is not ever NULL) in the RIGHT JOIN table to the WHERE clause this way: WHERE t2.idfield IS NULL
. So, the only time you should reference a table on the right side of the join is to find those records which are not in the table.