lovespring
lovespring

Reputation: 19589

SQL join syntax: put data filter in "on clause" or "where clasuse"?

for example, I have a sql query:

 select table1.*, table2.* from table1 
 left join table2 on table1.id=table2.id AND table2.someCol>123 (put it here)<p>
 where table2.someCol>123 (or put it here)

it seems that the two position all can put the filter condition, and is the SAME meaning, is it?

Upvotes: 0

Views: 60

Answers (1)

fancyPants
fancyPants

Reputation: 51938

No, it's not the same. It matters when you are left/right joining. If you put a where condition in the where clause referencing a left or right joined table, you basically turn it into an inner join. It would be a left or right join again, if you add OR referenced_left_or_right_joined_column IS NULL.

Upvotes: 5

Related Questions