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 8103045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:24:40+00:00 2026-06-05T23:24:40+00:00

I have a MySQL table with an auto-incremented integer primary key. I want to

  • 0

I have a MySQL table with an auto-incremented integer primary key. I want to get a bunch of rows from the table based on an array of integers I have in memory in my program. The array ranges from a handful to about 1000 items.

What’s the most efficient query syntax to get the rows?

I can think of a few:

  1. “SELECT * FROM thetable WHERE id IN (1, 2, 3, 4, 5)” (this is what I do now)
  2. “SELECT * FROM thetable where id = 1 OR id = 2 OR id = 3”
  3. Multiple queries of the form “SELECT * FROM thetable WHERE id = 1”. Probably the most friendly to the query cache, but expensive due to having lots of query parsing.
  4. A union, like “SELECT * FROM thetable WHERE id = 1 UNION SELECT * FROM thetable WHERE id = 2 …” I’m not sure if MySQL caches the results of each query; it’s also the most verbose format.

I think using the NoSQL interface in MySQL 5.6+ would be the most efficient way to do this, but I’m not yet up to MySQL 5.6.

  • 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-06-05T23:24:41+00:00Added an answer on June 5, 2026 at 11:24 pm

    No.1 is the fastest and easiest to maintain. So you’re already where you want to be.

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

Sidebar

Related Questions

I have a MySQL table of users whose primary key is an auto-incrementing integer
Assume the following in MySQL: CREATE TABLE users ( id integer auto_increment primary key,
I have one mysql table 'alfa' that will contain the primary key of another
I have a MySQL table with an autoincremented id column. The id started from
Hi I have a field in mySql table called jobnumber which auto increments with
In MySql I could have a table with an auto increment column and insert
I have a table in MySQL that for compatibility issues we assigned specific Primary
Sql: create table autori( id_autor integer primary key auto_increment, nume varchar(50) not null, prenume
I have users table and want to SELECT some rows by bitmask criteria. I'll
I have mysql table that has a column that stores xml as a string.

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.