SQL Server: Select in vs or?
11,930
Solution 1
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.
Solution 2
Actually it is the same.
If you display the estimated execution plan you will see that it is performing the same action.
![MCF](https://i.stack.imgur.com/ccSZe.jpg?s=256&g=1)
Author by
MCF
Updated on June 04, 2022Comments
-
MCF about 2 years
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 UserID = 4
-
Worgon about 11 yearsRather then Or/In is there any way to query? that will perform faster?
-
Martin Smith almost 10 years@Worgon if the number of values is large you could put the distinct values into an indexed temp table and join on that.
-
tbodt almost 10 yearsCan you please clarify that? I have no idea what you are saying.