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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:56:26+00:00 2026-05-19T11:56:26+00:00

I have a left join statement on 2 tables: tbl1 has about 1 million

  • 0

I have a left join statement on 2 tables: tbl1 has about 1 million records and tbl2 has about 20 million. The query takes about 9 seconds to execute. I have indexes on both but something doesn’t seem right given how long queries take. Here is my select statement:

EXPLAIN SELECT * FROM (SELECT tbl1.id, tbl1.name, tbl2.addr FROM tbl1 LEFT JOIN tbl2 ON tbl2.id = tbl1.id WHERE tbl1.name LIKE 'G%' AND tble2.addr IS NOT NULL) as tempTable GROUP BY id LIMIT 10;

+----+-------------+------------+--------+------------------+--------------+---------+----------------| 
id|select_type| table     |type  |poss_keys|key |key_len|ref         | rows | Extra 
+----+-------------+------------+--------+------------------+--------------+---------+----------------
1 | PRIMARY   | <derived2>|system| NULL    |NULL| NULL  |NULL        |    0 | const row not found |
2 | DERIVED   | tbl1      |range |id,name  |name| 903   |NULL        |    1 | Using where         |
2 | DERIVED   | tbl2      |ref   |id,addr  |id  | 4     |tbl2.tbl1.id|   25 | Using where         |
+----+-------------+------------+--------+------------------+--------------+---------+----------------

UPDATE:
If I take out the join statement & just select records from tbl1 or from tbl2 individually the select statements are fast (well under 1 second) but when I try to join them then it slows it down onsiderably…am I joining them correctly or do I need some kind of special index for joins?

  • 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-19T11:56:27+00:00Added an answer on May 19, 2026 at 11:56 am

    You might simplify it a bit… I don’t think you need a temp table or a group…

      SELECT tbl1.id, tbl1.name, tbl2.addr 
    FROM tbl1 LEFT JOIN tbl2 ON tbl2.id = tbl1.id 
    WHERE tbl1.name LIKE 'G%' AND tble2.addr IS NOT NULL
    

    Also…if the index doesn’t seem to be working you could add “tble2.id like ‘G%'”

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

Sidebar

Related Questions

I have a LEFT JOIN select statement that retrieves values from 2 tables: tableA
I have 4 tables and this query SELECT tag.id, title FROM tag LEFT JOIN
I have a MySQL Left Join problem. I have three tables which I'm trying
I have the following query SELECT e.topicShortName, d.catalogFileID, e.topicID FROM catalog_topics a LEFT JOIN
I want to join two tables together and have ONLY the data in Table
We have a transact sql statement that queries 4 tables with millions of rows
I'm using MySQL. I have 3 tables I'm trying to connect in a query
My issue is that I have a Select statement that has a where clause
We have two related tables (inventory, inventoryLocalization) and a t-sql query works on them
I'm trying to join two relatively simple tables together, but my query is experiencing

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.