IN & OR DIFFERECES

  • Hi Could any body plz help differece between IN And OR Clauses

    i hope both are give same result any differeces is there plz telme

    select * from employees where emp_id IN(10,20,30)

    select * from employees where employee_id=10 OR employee_id=20 OR employee_id=30

    Thanks

  • Yes. Both will give the same result.

    karthik

  • OR clause should use if you want to work with 2 or 3 values that you are searching the results with them!

    IN clause should use if you have more than 3 values for example 9-10 values that you are searching for the results with these values!

    Otherwise 2 clauses has the same function as said karthikeyan

    :hehe:

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Yes, both give the same result but, they won't always do so at the same speed.

    The second format (using the OR) is quicker (provided the column is indexed) so if you only have a small list then the OR method is best as the IN method will not use the index. (I think)

  • twillcomp (3/13/2009)


    Yes, both give the same result but, they won't always do so at the same speed.

    I don't think this is complete right. Since SQL Server 2005 they will do the same (in case of value listings). If you turn on to show the execution plan it will show you that the IN statement will be changed to an OR statement.

    In SQL Server 2008 IN statements are handled different; don't not yet now how :hehe: .

    Greets

    Flo

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply