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

后端 未结 9 1660
攒了一身酷
攒了一身酷 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:28

    I wouldn't use performance as the deciding factor here - and quite honestly, I don't think there's any measurable performance difference between those two cases, really.

    I would always use case #2 - why? Because in my opinion, you should only put the actual criteria that establish the JOIN between the two tables into the JOIN clause - everything else belongs in the WHERE clause.

    Just a matter of keeping things clean and put things where they belong, IMO.

    Obviously, there are cases with LEFT OUTER JOINs where the placement of the criteria does make a difference in terms of what results get returned - those cases would be excluded from my recommendation, of course.

    Marc

提交回复
热议问题