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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:00+00:00 2026-05-25T22:26:00+00:00

The Query: SELECT a FROM table1 WHERE b IN (SELECT b FROM table1 WHERE

  • 0

The Query:

SELECT a FROM table1 WHERE b IN (SELECT b FROM table1 WHERE c = 2);

If the subquery returns zero results, mysql takes a long time to realize it before it finally returns an empty result. (2.5s when subquery is empty, 0.0005s when there is a subquery result).

My question: is there a way to modify the query such that it will still return an empty result but take the same time as it did when there was a result?

I tried:

SELECT a FROM table1 WHERE b IN ((SELECT b FROM table1 WHERE c = 2), 555);

…but it only works WHEN the subquery is empty. If there is a result, the query fails.

— I don’t want to change the query format from nested to join/etc.

Ideas..? Thanks!

— EDIT: Also, I forgot to add: The subquery will likely result in a decent-sized list of results, not just one result. — ALSO, when I type ‘555’, I am referring to a value that will never exist in the column.

— EDIT 2: I also tried the following query and it “works” but it still takes several orders of magnitude longer than the original query when it has results:

SELECT a FROM table1 WHERE b IN (SELECT 555 AS b UNION SELECT b FROM table1 WHERE c = 2);
  • 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-25T22:26:00+00:00Added an answer on May 25, 2026 at 10:26 pm

    Wild guess (I can’t test it right now):

    SELECT a FROM table1 WHERE
    EXISTS (SELECT b FROM table1 WHERE c = 2)
    AND b IN (SELECT b FROM table1 WHERE c = 2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a mysql query like this: SELECT A.ID, A.NAME, B.ID, B.NAME FROM table1
Let's say I have this query: select * from table1 r where r.x =
I have the following query: SELECT rowid FROM table1 ORDER BY RANDOM() LIMIT 1
Do these two queries differ from each other? Query 1: SELECT * FROM Table1,
Given a query like: SELECT table1.field1 FirstField, table2.field2 SecondField FROM table1 INNER JOIN table2
Why this query doesn’t working: SELECT name FROM ( SELECT name FROM table1 UNION
My query string is like: SELECT ... FROM maintable LEFT JOIN table1 on (maintable.id
I have the following MySQL query: SELECT value_1, ( SELECT value_4 FROM table_1 WHERE
The following MySQL query: select `userID` as uID, (select `siteID` from `users` where `userID`
How do I specify the parent query field from within a subquery in MySQL?

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.