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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:02:59+00:00 2026-05-25T20:02:59+00:00

Assume that I have 2 tables : table1 :(20.000 records) id code1 code2 something

  • 0

Assume that I have 2 tables :

table1 :(20.000 records)
id    code1    code2   something    status

table2: (7.500 records)
id    code1    code2    name

All I want is list all records in table1 with the “name” in table2 by using this QUERY:

SELECT DISTINCT `tb1`.*, `tb2`.`name` FROM `table1` AS `tb1`
LEFT JOIN `table2` AS `tb2`
ON (tb1.code1 = tb2.code1 AND tb1.code2 = tb2.code2)
WHERE (tb1.status = 1)

But it took me too long to retreive the data (after 5 minutes I still cant see the result).

What is the best way to do this?

Thanks in advance..

  • 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-25T20:03:00+00:00Added an answer on May 25, 2026 at 8:03 pm

    Please try adding an index on table1 using columns(code1,code2,status). If you don’t have too many columns in table1, you can add them to the index too. In MS SQL, we have “include columns” that we can add to an index. Maybe mysql has something similar.

    Add an index on table2 using columns(code1,code2, name).

    If you are concerned about index size then just keep (code1, code2, status) for index1 and (code1, code2) for index2.

    Hope this helps.

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

Sidebar

Related Questions

To illustrate, assume that I have two tables as follows: VehicleID Name 1 Chuck
Consider the following Dig, Assume that all the three tables have a column Is_Deleted
I have the next task. Let's assume that we have below tables in a
Assume that we have two tables: Roles and Reports . And there exists a
I have two tables say ( FCT_SALES_SUMMARY_A and FCT_SALES_SUMMARY_B ). If we assume that
Let's assume that I have two tables... Foo and Bar. They contain the following
Assume that we have N erlang nodes, running same application. I want to share
Assume that you have a running SQL Server Express instance named (local)\SQLEXPRESS. Its database
Assume that I have this piece of code: @interface Foo : NSObject { Bar
Assume that we have multiple arrays of integers. You can consider each array as

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.