SQL Server IN vs. EXISTS Performance

前端 未结 9 912
醉酒成梦
醉酒成梦 2020-11-22 05:37

I\'m curious which of the following below would be more efficient?

I\'ve always been a bit cautious about using IN because I believe SQL Server turns th

9条回答
  •  醉梦人生
    2020-11-22 06:33

    I'd go with EXISTS over IN, see below link:

    SQL Server: JOIN vs IN vs EXISTS - the logical difference

    There is a common misconception that IN behaves equally to EXISTS or JOIN in terms of returned results. This is simply not true.

    IN: Returns true if a specified value matches any value in a subquery or a list.

    Exists: Returns true if a subquery contains any rows.

    Join: Joins 2 resultsets on the joining column.

    Blog credit: https://stackoverflow.com/users/31345/mladen-prajdic

提交回复
热议问题