in reply to What's an Efficient Way to Retrieve a Rank from a MySQL Table?
The principle being that someones rank is one more than the number of people that are better. I don't think MySQL supports nested SELECT statements, but you can always split the query into two. If you have an index on the 'grade' column (for simplicity, I assume such a column exists), the query should be pretty fast as the database doesn't need to do a table scan.SELECT 1 + COUNT(*) FROM student_data WHERE grade > (SELECT grade FROM student_data WHERE name = "whatever")
Abigail
|
|---|