There are 2 queries:
select a,b,c,d from test where a=1 or a=2 or a=3
and
select a,b,c,d from test where a in (1,2,3)
Which one performs better? In the table there is an index on column a.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
this should depend.
as you said in your comment, there are many variables.
the best way is to run some kind of explain plan for each specific query and see the difference (if there is any) on the specific database with the specific data loaded and the specific query.
stylistically, which is not the question, I personally prefer the IN clause in these cases.