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

后端 未结 6 1577
深忆病人
深忆病人 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:07

    1)

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

    In this, parser will check each row of t1 with each row of t2 with these 3 conditions. Getting faster result.

    2) SQL2: select t1.f1,t2.f2 from t1 left join t2 on t1.f1 = t2.f2 **where** t1.f2=1 and t1.f3=0

    In this, join only take 1st condition and then the result got from join is filtered with those 2 conditions. And will take more time than 1st query.

    You can get more from this link: http://ask.sqlservercentral.com/questions/80067/sql-data-filter-condition-in-join-vs-where-clause

提交回复
热议问题