SQL Filter criteria in join criteria or where clause which is more efficient

后端 未结 9 1657
攒了一身酷
攒了一身酷 2020-12-03 02:47

I have a relatively simple query joining two tables. The \"Where\" criteria can be expressed either in the join criteria or as a where clause. I\'m wondering which is more

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 03:34

    Case 1 (criteria in the JOIN) is better for encapsulation, and increased encapsulation is usually a good thing: decreased copy/paste omissions to another query, decreased bugs if later converted to LEFT JOIN, and increased readability (related stuff together and less "noise" in WHERE clause). In this case, the WHERE clause only captures principal table criteria or criteria that spans multiple tables.

提交回复
热议问题