Sunday, February 19, 2012

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 advancedepends 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

:)|||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).

No comments:

Post a Comment