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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:02:32+00:00 2026-06-01T07:02:32+00:00

I have two large tables in MySQL, one containing about 6,00,000 records and another

  • 0

I have two large tables in MySQL, one containing about 6,00,000 records and another containing about 90,000. I have one common field in these two tables on the basis of which I want to compare the records. I indexed both the tables on this common field but still query execution takes a very long time. Following is the query I used:

SELECT a.url,a.title,a.description,a.jobreferenceno,a.location,a.state,
    a.country,a.created_datetime,a.postalcode,a.company
FROM TABLE1 as a
WHERE EXISTS (
    select b.checkfield
    from TABLE2 as b where a.checkfield=b.checkfield
);

checkfield is the common column in both the tables.

Any suggestions on how to speed it up?

  • 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-01T07:02:34+00:00Added an answer on June 1, 2026 at 7:02 am

    subqueries, like the EXISTS subquery you used here, are notoriously slow in MySQL. You should convert them to a JOIN if you have the chance. A JOIN query for your example would look like this:

    SELECT a.url
    ,a.title
    ,a.description
    ,a.jobreferenceno
    ,a.location
    ,a.state
    ,a.country
    ,a.created_datetime
    ,a.postalcode
    ,a.company 
    FROM TABLE1 as a 
    INNER JOIN TABLE2 as b 
    ON         a.checkfield = b.checkfield
    

    (Note that this is not entirely the same as your original: here, any row from TABLE1 for that matches multiple rows in TABLE2 will be returned multiple times. If checkfield is unique in both tables, the result will be the same.)

    That said, it is unclear how this really helps – you’re not really comparing rows here, simply selecting those rows from TABLE for which there is at least one row in TABLE2 that happens to have the same value in checkfield

    (at any rate, checkfield should be indexed in both tables to help the efficiency of these queries )

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

Sidebar

Related Questions

I face the following problem. I have two large tables with about 80.000 records
I have three large MySQL tables. They are approaching 2 million records. Two of
I have two quite large tables, let's call them 'authors' and 'articles'. Every row
I have a large database with two tables: stat and total. The example of
I have two large identical-sized files. One is ASCII plain text, and the other
I have two large source trees. One of them has some out of date
I have two databases in SQL2k5: one that holds a large amount of static
I have two tables, both having more than 20 million records; table1 is a
I have 2 related MySQL tables in a one to many relationship. Customers: cust_id,
I have two parent tables, BusinessGroup and SocialGroup, and one child table, Members. A

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.