SQL Server Performance

IN/OR performance difference

Discussion in 'SQL Server 2005 T-SQL Performance Tuning' started by MikeS, Jan 29, 2007.

  1. MikeS New Member

    Is there any performance difference between using an "in" statement or multiple "or" statements?

    EX:

    USE Northwind

    select * from Invoices
    where ProductID in (14,51,22,57)

    select * from Invoices
    where ProductID = 14 or ProductID = 51 or ProductID = 22 or ProductID = 57
  2. Roji. P. Thomas New Member

    No. When a list of values are supplied, SQL Server internally replaces the IN with multiple ORs.
    With a subquery, its a different story,

    Roji. P. Thomas
    SQL Server MVP
    http://toponewithties.blogspot.com
  3. joechang New Member

    sometimes you will also see that the in list is converted to a rowset which can be joined to other tables

Share This Page