What's the difference between where clause and on clause when table left join?

后端 未结 6 1552
深忆病人
深忆病人 2020-11-27 18:28

SQL1:

select t1.f1,t2.f2 
from t1 
   left join t2 on t1.f1 = t2.f2 and t1.f2=1 and t1.f3=0 

SQL2:

select t1.f1,t2.f2 
from         


        
6条回答
  •  旧巷少年郎
    2020-11-27 19:02

    The first query is quicker than the second one as the join condition is more specific than the second one: it does not makes sense to return records that you will filter with the where clause (it would be better do not return them at all- query1)

    Anyway it really depends by the query optimizer.

    have a look at the below:

    Is a JOIN faster than a WHERE?

提交回复
热议问题