In an INNER JOIN
, you could use the ON
and WHERE
interchangebly, just a case of preference really. The underlying logic doesn't change and it also doesn't have an impact of the execution plan as well.
Its quite different for the OUTER JOINs
.
a. Filter Criteria in the WHERE
Clause i.e.
SELECT * FROM A left join B
ON A.id=B.id
WHERE B.id=1
The above query will function like an INNER JOIN
and limit the entire result only to the row with B.id=1 (Note that the filter is applied to the table on the right of the LEFT JOIN
operator)
b. Filter Criteria in the ON
Clause i.e.
SELECT * FROM A left join B
ON A.id=B.id
AND B.id=1
The above query will only limit the rows of table B as they are being mapped to table A
in the LEFT JOIN
operator. So the result will contain all rows of table A
and values in the columns for table B
only for the rows that match the condition B.id=1
Credit to @Abraham - here is the SQLFIDDLE for the same