Is there a logical difference between putting a condition in the ON clause of an inner join versus the where clause of the main query?

前端 未结 3 582
旧时难觅i
旧时难觅i 2021-01-06 03:33

Consider these two similar SQLs

(condition in ON clause)

select t1.field1, t2.field1
from
table1 t1 inner join table2 t2 on t1.id = t2.id and t1.bool         


        
3条回答
  •  温柔的废话
    2021-01-06 04:15

    In your specific case, the t1.boolfield specifies an additional selection condition, not a condition for matching records between the two tables, so the second example is more correct.

    If you're speaking about the cases when a condition for matching records is put in the ON clause vs. in the WHERE clause, see this question.

提交回复
热议问题