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
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ctrlShiftBryan
  • 27,092
  • 26
  • 73
  • 78

3 Answers3

26

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.

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
8

Actually it is the same.

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

David Espart
  • 11,520
  • 7
  • 36
  • 50
-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'.