I'm using MySQL and I have a table that holds player scores, with a single player being able to log multiple scores. I'm trying to find the best way to rank the players using the MySQL ORDER BY keyword.
Right now what I'm doing is:
SELECT DISTINCT t.userName FROM (SELECT userName, score FROM scoreTable ORDER BY score DESC) t;
To use this for ranking it I'm assuming that the order from the sub-query is maintained by the main query.
Is this assumption correct? All my testing so far maintains the order properly. Is there a situation where it will not work?
I don't believe this is guaranteed behavior, but generally yes. It may be better to have the ORDER BY
on the outer query if you want the final results ordered that way.