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

  • Home
  • SEARCH
  • 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 9113079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:53:13+00:00 2026-06-17T03:53:13+00:00

I have a simple QUERY with an INNER JOIN. The tables that are joined

  • 0

I have a simple QUERY with an INNER JOIN. The tables that are joined have 1500 en 2500 rows. Both tables have a primary key. The join is not done on this key.

The result set of this query has 1500rows.
When I run this query it takes 20 seconds… (AN ETERNITY)

SELECT so.order_id
FROM   shop_orders so
       INNER JOIN shop_order_payments sop
          ON so.order_code = sop.order_code
WHERE  sop.status = 9
ORDER  BY date_created DESC

When I then add the ” LIMIT 1500 ” at the end , the query takes only 1sec.
(When I remove it it takes again 20 seconds so it’s not the cache…)

  1. Why is this ?
  2. And is there a fast way to find out how many rows this query has as a result?

note: I run this query in a php script with the mysql() function )

*update1: The result of the EXPLAIN

id   select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE  sop ALL NULL    NULL    NULL    NULL    1153    Using where; Using temporary; Using filesort
1   SIMPLE  so  ALL NULL    NULL    NULL    NULL    2529    Using where

  • Update 2:

I ran DESC as requested in the comments


payment_id - int(11)    NO  PRI     auto_increment
timestamp - timestamp   NO      CURRENT_TIMESTAMP   
order_code - varchar(100)NO         
acceptance - varchar(50) NO         
amount  -  varchar(20)  NO          

So only a primary index shows up, this is not enough as an index?

  • 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-17T03:53:15+00:00Added an answer on June 17, 2026 at 3:53 am

    The EXPLAIN tells that the query is using no index. Thus it performs fulltable scan causing it to be slow.

    try to run this statements,

    ALTER TABLE shop_orders ADD INDEX td_idx (order_code);
    ALTER TABLE shop_order_payments ADD INDEX td2_idx (order_code);
    

    and run the SELECT query again.

    UPDATE 1

    Your table has an index but on column payment_id which in this case isn’t used since the join is using column order_code. You must also define an index on that column.

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

Sidebar

Related Questions

I have a simple query that relies on two full-text indexed tables, but it
Here is the simple sql query that will return all tables that have the
I have a simple JOIN query: $lstCheck = $dbWHMCS->query('SELECT * FROM tblmonitorports mp INNER
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
I have a simple query that finds cities that are within a certain distance
I have a simple query tied to a command button that shows a summary
I have a simple query (in a mySQL view) that php is using to
I have a simple query: $query = new WP_Query('showposts=5'); that will obviously display 5
I have a MySQL query that I'd like help optimizing. Its rather simple in
We have three tables that we would like to query to find out the

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.