Interviews - C# Corner

Swati Agarwal
Which will be faster out of these two queries - one with OR or one with IN?
By Swati Agarwal in SQL Server on Nov 21, 2012
  • RAHUL SHUKLA
    Jul, 2015 28

    In. If the column is indexed then no difference but if the column is not indexed then the In would be faster than OR because it first sort the record then apply the binary search.

    • 1
  • Ajay suwalka
    May, 2013 6

    Almost no difference.. Just checked it on 65000 rows with random values. Values are compared separately at run time whether they are using IN CLAUSE or using OR CLAUSE in query sql server usage same mechanism for both.

    • 1
  • Mahesh Patel
    Nov, 2012 27

    IN. Because While you use "OR" condition that means your sql select two set of record of index while "IN" is select one record set as per index

    • 1
  • Vishal Jadav
    Aug, 2016 8

    the query with OR is more faster than IN.

    • 0
  • Nitin Sontakke
    Jul, 2016 30

    SQL Server query engine expands all values in IN into a separate OR condition and then executes the query. As Jamie King says it, IN is just a syntactic sugar for less typing for the end user.

    • 0
  • Sandeep Kumar
    Jun, 2016 18

    In query is faster than OR

    • 0
  • Joginder Banger
    Nov, 2014 10

    IN query is fast rather then OR condition.

    • 0
  • Manju lata Yadav
    Jul, 2014 11

    They have difference in Argument types. IN:- test_expression Is any valid expression. subquery Is a subquery that has a result set of one column. This column must have the same data type as test_expression. expression[ ,... n ] Is a list of expressions to test for a match. All expressions must be of the same type as test_expression. OR :- boolean_expression Is any valid expression that returns TRUE, FALSE, or UNKNOWN.

    • 0

VSLive! Anaheim

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS