Sample Header Ad - 728x90

Get the rank of a user in a score table

39 votes
10 answers
162190 views
I have a very simple MySQL table where I save highscores. It looks like that: Id Name Score So far so good. The question is: How do I get what's a users rank? For example, I have a users Name or Id and want to get his rank, where all rows are ordinal ordered descending for the Score. An Example Id Name Score 1 Ida 100 2 Boo 58 3 Lala 88 4 Bash 102 5 Assem 99 In this very case, Assem's rank would be 3, because he got the 3rd highest score. The query should return one row, which contains (only) the required Rank.
Asked by Michael (595 rep)
Feb 22, 2012, 08:48 PM
Last activity: Jul 24, 2021, 07:21 AM