I am implementing leaderboards in a game based on very good tutorial.
I am quite new to MySQL, but I got some basics. But there is a part of the code which I am totally clueless how actually works and because I don't want to implement something which doesn't make any sense to me I wanted to ask if someone could please help me understand this. It handles returning player's rank in the leaderboards:
SELECT uo.*,
(
SELECT COUNT(*)
FROM Scores ui
WHERE (ui.score, -ui.ts) >= (uo.score, -uo.ts)
) AS rank
FROM Scores uo
WHERE name = '$name';
My understanding is that first everything in the Scores table gets selected, then amount of rows gets selected, I don't understand how that selection works tho, how is the WHERE working is totaly beyond me with the timestamp. And then I am not sure how it works all together.