IN vs. JOIN with large rowsets

前端 未结 12 1751
天命终不由人
天命终不由人 2020-11-30 20:45

I\'m wanting to select rows in a table where the primary key is in another table. I\'m not sure if I should use a JOIN or the IN operator in SQL Server 2005. Is there any si

12条回答
  •  生来不讨喜
    2020-11-30 21:24

    The IN is evaluated (and the select from b re-run) for each row in a, whereas the JOIN is optimized to use indices and other neat paging tricks...

    In most cases, though, the optimizer would likely be able to construct a JOIN out of a correlated subquery and end up with the same execution plan anyway.

    Edit: Kindly read the comments below for further... discussion about the validity of this answer, and the actual answer to the OP's question. =)

提交回复
热议问题