20

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
1

3 Answers 3

25

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.

2
  • 1
    Rather then Or/In is there any way to query? that will perform faster?
    – Worgon
    Jun 11, 2013 at 6:33
  • 1
    @Worgon if the number of values is large you could put the distinct values into an indexed temp table and join on that. Sep 13, 2014 at 19:18
7

Actually it is the same.

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

-1

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'.

1
  • Can you please clarify that? I have no idea what you are saying.
    – tbodt
    Sep 13, 2014 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.