ORDER BY slows my query to a crawl.
While digging through StackOverflow trying to fix this, I've found several references to wrapping one's query with 'SELECT *'. For some unfathomable reason, this ALSO slows my query to a crawl.
I don't understand how wrapping my query this way should have any effect. Shouldn't SELECT * FROM (QUERY) be identical to QUERY?
This is my query:
SELECT W.NDB_No, Seq, Gm_Wgt*Nutr_Val/100
FROM WEIGHT AS W,
(SELECT NDB_No, Nutr_No FROM FOOD_DES, NUT ORDER BY nutrEnum) AS A
LEFT JOIN
NUT_DATA AS B
ON A.NDB_No = B.NDB_No AND A.Nutr_No = B.Nutr_No;
It takes 0.8 seconds. Wrapping this query with SELECT * FROM (...) AS X
slows the query down tremendously. What is going on here? Also, any help for getting ORDER BY to work would be greatly appreciated (probably a related problem). Please see SQL Fiddle here.