Kamlesh_Rathore Posted August 19, 2013 Share Posted August 19, 2013 (edited) SELECT train_no,train_nameFROM trainsWHERE train_noIN (SELECT s1.train_noFROM train_schedule AS s1INNER JOIN train_schedule AS s2WHERE s1.stn_code = 'JU'AND s2.stn_code = 'JP'AND s1.distance < s2.distanceAND s1.train_no = s2.train_no) ORDER BY train_no LIMIT 0 , 30this query takes 50 seconds to executes on my serveri want quick responseplease help what kind of changes i should done Edited August 19, 2013 by Kamlesh_Rathore Quote Link to comment https://forums.phpfreaks.com/topic/281353-my-mysql-query-optimizationexecute-query-fast/ Share on other sites More sharing options...
Barand Posted August 19, 2013 Share Posted August 19, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/281353-my-mysql-query-optimizationexecute-query-fast/#findComment-1445805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.