Results 1 to 3 of 3

Thread: IN vs OR

  1. #1
    Join Date
    Mar 2003
    Location
    France
    Posts
    21

    Unanswered: IN vs OR

    someone can tell me if
    SELECT ... WHERE myField IN (1,2,3)
    is more efficient than
    SELECT ... WHERE (myField = 1) OR (myField = 2) OR (myField = 3)

    thanks in advance

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    depends on your database, but in general, they will be exactly the same

    the IN is easier to write, though, easier to read, and easier to maintain, isn't it

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    I guess the query will run better if there's an index on 'myfield' column; IN compared to multiple ORs doesn't improve execution at all (at least, that's what a quick example on Oracle database (its explain plan and statistics) showed).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •