Adam Adam - 15 days ago 5
MySQL Question

MySQL Slow Query - Order By

I have the following SELECT that runs in under a second if I remove the ORDER BY at the end. With the ORDER BY it runs in around 9 seconds.

I have a ruff understanding that some other SQL commands like '< >' comparison operators can work adversely with an ORDER BY.

I've tried commenting out lines and can improve the performance to say 2-3seconds with the ORDER BY but still without the ORDER BY its more like under 1 second.

Can someone give me some good advise on how to better write this query, what to avoid etc? All advise is greatly appreciated.

thankyou

Answer

please try:

SELECT * FROM (
SELECT 

LIMIT 120;