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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:08:05+00:00 2026-05-27T06:08:05+00:00

Is the syntax of this query SELECT * FROM table1 WHERE var_c IN( SELECT

  • 0

Is the syntax of this query

SELECT * FROM  table1
WHERE var_c IN(
SELECT var_a FROM table2 
WHERE var_b =55554444
);

Equivalent to this?

SELECT table1.* FROM table1, table2
WHERE (table2.var_a=table1.var_c AND table2.var_b=55554444);

The first one takes about 7-8 seconds to run and the 2nd one takes about .75 seconds to run. When I use a Join statement it takes about 4-5 seconds to run.

Also is the syntax of this

DELETE FROM  table1
WHERE var_c IN(
SELECT var_a FROM table2 
WHERE var_b =55554444
);

And this:

DELETE table1.* FROM table1, table2
WHERE (table2.var_a=table1.var_c AND table2.var_b=55554444);

The same?

  • 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-27T06:08:06+00:00Added an answer on May 27, 2026 at 6:08 am

    No, the 2 queries are not equivalent. The second can return duplicate rows, if (var_a, var_b) is not UNIQUE in table2

    The first query though:

    SELECT * 
    FROM  table1
    WHERE var_c IN
          ( SELECT var_a 
            FROM table2 
            WHERE var_b =55554444
          )
    

    and if table2.var_a does not contain any NULL values, then it’s equivalent to this:

    SELECT table1.* 
    FROM table1
       , table2
    WHERE table2.var_a = table1.var_c 
      AND table2.var_b = 55554444
    GROUP BY table1.PK                --- Primary Key of table1
    

    (which is better to be written with explicit JOIN syntax as:

    SELECT table1.* 
    FROM table1
      JOIN table2
        ON table2.var_a = table1.var_c 
    WHERE table2.var_b = 55554444
    GROUP BY table1.PK                --- Primary Key of table1
    

    and this:

    SELECT * 
    FROM  table1
    WHERE EXISTS 
          ( SELECT *
            FROM table2 
            WHERE table2.var_b = 55554444
              AND table2.var_a = table1.var_c
          )
    

    About performance, the best advice you could get is to test, test and test again with your data. Try with different indexes and figure how to read the EXPLAIN plans.

    You’ll probably find that IN (SELECT ... FROM ...) has not the best performance with current MySQL optimizer (although I hear that MariaDB plans some major improvements in next release, Maria 5.3) and that JOIN and EXISTS variants perform usually better.

    But this heavily depends on the indexes you have on the tables. Without any index, all of them will be slow. And query time < 1 sec does not mean it’s fast. With a billion rows in the tables, yes, it’s pretty good. For a table with only a few thousand rows, time < 0.01 sec should be expected.

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

Sidebar

Related Questions

Consider this simple query: SELECT * FROM table1 JOIN table2 USING(pid) WHERE pid='2' ;
This query fails: SELECT xpath('/my/xpath/expr', my_xml)[1] FROM my_table ERROR: syntax error at or near
I have the following MySql query: select t1.* from Table1 t1 inner join Table2
This query gives me syntax error in when-between line. how can i solve them?
Buried in mySQL syntax and query structure problems once more. I'm currently doing this
Basic C# syntax question: So I have this class public class BrandQuery<T> : Query<T>
I have this syntax which works (since it's from the API, pretty much) <%
I try to execute this query in my CompanyRepository $qb = $this->_em->createQueryBuilder(); $qb->select(array('c', 'ld'))
I have two columns syntax and query in my table Table1 . Syntax contains
This is my query update b set b.col1 = if(1) <= 0 begin select

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.