Difference between filtering queries in JOIN and WHERE?

前端 未结 3 614
后悔当初
后悔当初 2020-12-04 12:38

In SQL I am trying to filter results based on an ID and wondering if there is any logical difference between

SELECT value 
FROM table1 
JOIN table2 ON table1         


        
3条回答
  •  长情又很酷
    2020-12-04 13:22

    I think answer marked as "right" is not right. Why? I try explain:

    We have opinion

    "Always keep the Join Conditions in ON clause Always put the filter's in where clause"

    And this is wrong. If you are in inner join, every time put filter params in ON clause, not in where. You ask why? Try imagine complex query with total of 10 tables(f.e. every table has 10k recs) join, with complex WHERE clause(for example, functions or calculations used). If you put filtering criteria in ON clause, JOINS between these 10 tables not occurs, WHERE clause will not executed at all. At this case you are not performing 10000^10 calculations in WHERE clause. This make sense, not putting filtering params in WHERE clause only.

提交回复
热议问题