SQL Server: Select in vs or?

后端 未结 3 1777
执念已碎
执念已碎 2020-12-16 12:03

Which is faster?

SELECT UserName
FROM dbo.UserTable
WHERE UserID in (1,3,4)

SELECT UserName
FROM dbo.UserTable
WHERE UserID =         


        
相关标签:
3条回答
  • 2020-12-16 12:29

    This is relevant when it comes to producing SQL via Linq. There are some instances where the sql created is in the form of: field='xxx' OR field='yyy'.

    0 讨论(0)
  • 2020-12-16 12:37

    Due to Sql Server's optimization of queries these will run at the same speed since they are logically equivalent.

    i favor the IN syntax for brevity and readability though.

    0 讨论(0)
  • Actually it is the same.

    If you display the estimated execution plan you will see that it is performing the same action.

    0 讨论(0)
提交回复
热议问题