• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 803
  • Last Modified:

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



0
jacobbdrew
Asked:
jacobbdrew
2 Solutions
 
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
 
profyaCommented:
SET @rank=0;
SELECT score, (@rank:=@rank+1) as 'rank'
FROM tbl_scores
ORDER BY score;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now