Difference between ON and WHERE clauses in SQL table joins

后端 未结 5 1435
小蘑菇
小蘑菇 2020-12-30 14:10
select e.last_name, e.hire_date
from employees e join employees m
on (m.last_name = \'Davies\')
and (e.hire_date > m.hire_date);

select e.last_name, e.hire_date
         


        
5条回答
  •  春和景丽
    2020-12-30 14:44

    where is a filter which is applied after rows are selected using the join. It is not always the case that a join ... on condition is sematically equivalent to a where condition. Therefore, yes, there is a particular reason to use a where in table joins: when it does the right thing.


    ...and by contrast, the ON condition executes as the join is being made. ON conditions for joins earlier in multi-table joins can cut off millions of unnecessary joins so are generally preferred if semantically correct
    – Bohemian

提交回复
热议问题