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

  • SEARCH
  • Home
  • 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 4553288
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:55:27+00:00 2026-05-21T16:55:27+00:00

I have an InnoDB table and an index on age column just like this

  • 0

I have an InnoDB table and an index on age column just like this

   CREATE TABLE Person (

      ....
      age int(11) not null;
      key (age);
      ....
   ) engine=InnoDB;

I just want to know the real things behind these queries:

SELECT * FROM Person WHERE age IN [1, 2, 3];

and

SELECT * FROM Person WHERE age BETWEEN 1 AND 3;

As what I’ve learnt, the first one MySQL will use the index on column age while the second one it can’t use. Is it? Which is better for performance?

  • 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-21T16:55:28+00:00Added an answer on May 21, 2026 at 4:55 pm

    Both queries will use an index.

    Query A will translated to:

    select * from person where age = 1 or age = 2 or age 3;
    

    Query B will translate to

    select * from person where age >= 1 and age <= 3;
    

    So query A will do 3 tests using OR.
    Query B will do 2 tests using AND.

    Query B is faster.

    In general, queries using AND are faster than queries using OR.
    Also Query B is doing fewer tests and because it’s testing a range it can more easily exclude results that it does not want.

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

Sidebar

Related Questions

I have a table looking like this: CREATE TABLE `item` ( `id` int(11) NOT
I have this schema: CREATE TABLE `lotto`.`combinaciones` ( `indice` mediumint(8) unsigned NOT NULL, `binario`
I have the talbe like that: CREATE TABLE UserTrans ( `id` int(10) UNSIGNED NOT
I have a view like this: CREATE VIEW MyView AS SELECT Column FROM Table
I have a table course: CREATE TABLE course (COURSE_NO NUMERIC(8,0) NOT NULL ,DESCRIPTION VARCHAR(50)
I have a table called users: CREATE TABLE `users` ( `UID` INT UNSIGNED NOT
I have recursive table: CREATE TABLE IF NOT EXISTS `Table1` ( `Id_table1` INT UNSIGNED
CREATE TABLE IF NOT EXISTS `mydb`.`MATCHES` ( `idMatch` INT NOT NULL , `idChampionship` INT
I have the following MySQL/InnoDB table. I added a compound index as the primary
I have MySQL InnoDB table utf-8 encoded. This table has only id and name

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.