Skip to content
Advertisement

How to create a MySQL 5.6 Rank with JOIN and multiple sorting criteria

I am stuck trying to return the rank of an SQL query.

The final row should show the rank of the sorting that is presented correctly. I should be seeing Rank = 1,2,3 but I get this instead … I’ve tried numerous variations of the SQL statement but I cannot strike on the solution.

Ideally, I would use this query to:

Advertisement

Answer

I would recommend joining and ordering in a subquery first, then computing the rank. Also, you should not mix implicit and explicit joins – matter of fact, always use explicit joins:

Note that, if you are running MySQL 8.0, this is straight-forward with row_number():

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement