How Do I include the current row in a mysql select statement

Hi Experts--

The question title says it all. basically i have a list of scores, i want to select them in order and add a rank column to the result. something like this:

SELECT score, CURRENT_ROW as 'rank'
FROM tbl_scores
ORDER BY score

i don't think CURRENT_ROW is actually a variable in MySQL. I need to know what to use in it's place

-thanks

jacob



LVL 1
jacobbdrewAsked:
Who is Participating?
 
profyaCommented:
SET @rank=0;
SELECT score, (@rank:=@rank+1) as 'rank'
FROM tbl_scores
ORDER BY score;
0
 
nguyenvinhtuCommented:
Try this friend. Or you can write something similar to this in your MySQL

SELECT score, (SELECT COUNT(*) FROM tbl_scores B WHERE B.score <= A.score) as 'rank'
FROM tbl_scores A
ORDER BY score
Sincerely yours
Danny
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.