Possible Duplicate:
Is there a performance difference between BETWEEN and IN with MySQL or in SQL in general?
If I have the following ids:
1,2,3,4,5,6
Is it better to use IN or the between clause for deleting?
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.
BETWEEN.IN.Performance shouldn’t really be the deciding factor here. Having said that, BETWEEN seems to be faster in all examples that I have tested. For example:
Without indexes, checking a table with a million rows where every row has x = 1:
Without indexes, checking a table with a million rows where x has unique values:
A more realistic example though is that the id column is unique and indexed. When you do this the performance of both queries becomes close to instant.
So I’d say concentrate on writing a clear SQL statement rather than worrying about minor differences in execution speed. And make sure that the table is correctly indexed because that will make the biggest difference.
Note: Tests were performed on SQL Server Express 2008 R2. Results may be different on other systems.