Jump to content

my mysql query optimization,execute query fast


Kamlesh_Rathore

Recommended Posts

SELECT train_no,train_name
FROM trains
WHERE train_no
IN (

SELECT s1.train_no
FROM train_schedule AS s1
INNER JOIN train_schedule AS s2
WHERE s1.stn_code = 'JU'
AND s2.stn_code = 'JP'
AND s1.distance < s2.distance
AND s1.train_no = s2.train_no
) ORDER BY train_no LIMIT 0 , 30


this query takes 50 seconds to executes on my server
i want quick response

please help what kind of changes i should done

Does this help

SELECT t.train_no, t.train_name
FROM trains t
    INNER JOIN train_schedule AS s1 
        ON t.train_no = s1.train_no AND s1.stn_code = 'JU'
    INNER JOIN train_schedule AS s2
        ON t.train_no = s2.train_no AND s2.stn_code = 'JP'
WHERE s1.distance < s2.distance
ORDER BY train_no 
LIMIT 0 , 30

If not, can you post a test dump of the two  tables

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.