开发者

SQL Server: Select in vs or?

开发者 https://www.devze.com 2022-12-16 22:49 出处:网络
Which is faster? SELECT UserName FROM dbo.UserTable WHERE UserID in (1,3,4) SELECT UserName FROM dbo.UserTable

Which is faster?

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

SELECT UserName
FROM dbo.UserTable
WHERE UserID = 1 
      OR UserID = 3
      OR UserI开发者_运维百科D = 4


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.


Actually it is the same.

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


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

精彩评论

暂无评论...
验证码 换一张
取 消