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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:45:23+00:00 2026-05-23T19:45:23+00:00

is there any performance difference between: SELECT * FROM table WHERE id IN (1,2,3)

  • 0

is there any performance difference between:

SELECT * FROM table WHERE id IN (1,2,3)

versus

SELECT * FROM table WHERE id = 1
SELECT * FROM table WHERE id = 2
SELECT * FROM table WHERE id = 3

whereby you execute each query, so there are 3 total queries to be executed by PHP

  • 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-23T19:45:23+00:00Added an answer on May 23, 2026 at 7:45 pm

    Both of the examples provided do different things although they may look similar. Use the construct designed to do what you want. Worrying about “optimization” here is silly and premature: a good model and good design should come first.

    The first case is one query — it returns one result set (of presumably up to 3 items, assuming that ID is a PK). The order of records in the set is not defined as there is no ORDER BY.

    The second case has three queries — and thus three result sets (the order of the result sets in relationship to each-other is defined) — each result set (assuming again that ID is a PK) will result in 0 or 1 records.

    Now, if only it were that simple… depending on whether the second was executed inside a transaction or not (and what isolation level of transaction and what guarantees the backend makes) determines if the same items are guaranteed to be returned in both cases. That is, imagine the record with ID=2 is deleted after the SELECT ID=1 but before SELECT ID=2 — what should the results be?

    All that being said, the “correct” choice is likely the single select, although it is possible to imagine pathological cases where the second is desired. As a bonus, it is also generally easier to deal with a single result set.

    I suspect the first case will also be [slightly] better performing just because of the small overheads for query execution and, in any case, it should be no slower than the second. The difference in performance may or may not be negligible depending upon other factors including connection latency. However, the only way to know “for certain” is to run performance tests on actual data/usage and inspect query plans (see EXPLAIN).

    Happy coding.

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

Sidebar

Related Questions

Is there any performance difference between the two following queries: SELECT foo,bar FROM table
In Microsoft SQL, is there any difference in performance between this: SELECT columns FROM
Is there any performance difference between the following two statements? from item in collection
Is there any performance difference between tuples and lists when it comes to instantiation
Is there any performance difference between the for loops on a primitive array? Assume:
What is the main difference between StringBuffer and StringBuilder ? Is there any performance
Is there any difference in performance between the operator IS NULL and the function
Is there any performance difference between: size.width += this->font->chars[*ch].advance + this->font->chars[*ch].offset.x; and char_data *chars
Here's a simple question : Is there any (performance) difference between this : Person
I just wanted to know that is there any performance difference between these two

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.