Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 954855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:17:01+00:00 2026-05-16T00:17:01+00:00

Possible Duplicate: Is there a performance difference between BETWEEN and IN with MySQL or

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:17:01+00:00Added an answer on May 16, 2026 at 12:17 am
    • If your ids are always consecutive you should use BETWEEN.
    • If your ids may or may not be consecutive then use 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:

    SELECT COUNT(*) FROM table1 WHERE x IN (1, 2, 3, 4, 5, 6);
    Time taken: 0.55s
    
    SELECT COUNT(*) FROM table1 WHERE x BETWEEN 1 AND 6;
    Time taken: 0.54s
    

    Without indexes, checking a table with a million rows where x has unique values:

    SELECT COUNT(*) FROM table1 WHERE x IN (1, 2, 3, 4, 5, 6);
    Time taken: 0.65s
    
    SELECT COUNT(*) FROM table1 WHERE x BETWEEN 1 AND 6;
    Time taken: 0.36s
    

    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.

    SELECT COUNT(*) FROM table2 WHERE x IN (1, 2, 3, 4, 5, 6);
    Time taken: 0.00s
    
    SELECT COUNT(*) FROM table2 WHERE x BETWEEN 1 AND 6;
    Time taken: 0.00s
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is there a performance difference between i++ and ++i in C++? I
Possible Duplicate: Is there a performance difference between i++ and ++i in C++? In
Possible Duplicate: Is there a performance difference between i++ and ++i in C++? They
Possible Duplicate: Difference between i++ and ++i in a loop? Is there a performance
Possible Duplicate: Is there a REAL performance difference between INT and VARCHAR primary keys?
Possible Duplicate: Is there a performance difference between i++ and ++i in C++? Is
Possible Duplicate: Is there a performance difference between i++ and ++i in C++? I
Possible Duplicate: Is there a performance difference between i++ and ++i in C++? In
Possible Duplicate: Is there any hash function in PL/SQL? I have a column with
Possible Duplicate: Is there a difference between single and double quotes in Java? I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.