title: How to get ranking of scores in MySQL with LIMIT?
body: <p>This is what I currently have: </p>
  
  <pre><code>SELECT id, score, username,
  CASE
  WHEN @prevRank = score THEN @curRank
  WHEN @prevRank := score THEN @curRank := @curRank + 1
  END AS rank
  FROM users u,
  SELECT @curRank :=0, @prevRank := NULL) r
  ORDER BY score DESC LIMIT 5, 5;
  </code></pre>
  
  <p>I want the next 5 ranks from row 5, but the ranking restarts at 1. How can I get the ranking to start at the correct ranking relative to all the rows?</p>
  
  <p>Sample data: <a href="http://pastebin.com/i3PsRWdg" rel="nofollow">http://pastebin.com/i3PsRWdg</a></p>
  
  <pre><code>Everyone
  
  +----+--------+-----------+------+
  | id | scores | username  | rank |
  +----+--------+-----------+------+
  | 24 |     23 | fl        |    1 |
  |  3 |      9 | test      |    2 |
  |  6 |      9 | usernine  |    2 |
  |  5 |      7 | test3     |    3 |
  | 11 |      7 | test9     |    3 |
  | 26 |      5 | tryagain  |    4 |
  | 12 |      5 | newUser   |    4 |
  |  7 |      3 | test6     |    5 |
  | 14 |      1 | new3      |    6 |
  |  4 |      1 | test2     |    6 |
  | 13 |      0 | new2      | NULL |
  | 25 |      0 | newu      |    6 |
  | 23 |      0 | new       |    6 |
  | 22 |      0 | usernine  |    6 |
  | 21 |      0 | usernine  |    6 |
  | 20 |      0 | test      |    6 |
  | 19 |      0 | usernine  |    6 |
  | 18 |      0 | usernine  |    6 |
  | 17 |      0 | usernine  |    6 |
  | 15 |      0 | usernine  |    6 |
  | 16 |      0 | test9     |    6 |
  +----+--------+-----------+------+
  
  LIMIT 1,5 -&gt; correct
  
  +----+--------+-----------+------+
  | id | scores | username  | rank |
  +----+--------+-----------+------+
  |  3 |      9 | test      |    1 |
  |  6 |      9 | usernine  |    1 |
  |  5 |      7 | test3     |    2 |
  | 11 |      7 | test9     |    2 |
  | 26 |      5 | tryagain  |    3 |
  +----+--------+-----------+------+
  
  LIMIT 5,5 -&gt; incorrect
  
  +----+--------+----------+------+
  | id | scores | username | rank |
  +----+--------+----------+------+
  | 12 |      5 | newUser  |    1 |
  | 26 |      5 | usernine |    1 |
  |  7 |      3 | test6    |    2 |
  |  4 |      1 | test2    |    3 |
  | 14 |      1 | new3     |    3 |
  +----+--------+----------+------+
  
  Should be this:
  
  +----+--------+----------+------+
  | id | scores | username | rank |
  +----+--------+----------+------+
  | 12 |      5 | newUser  |    4 |
  | 26 |      5 | usernine |    4 |
  |  7 |      3 | test6    |    5 |
  |  4 |      1 | test2    |    6 |
  | 14 |      1 | new3     |    6 |
  +----+--------+----------+------+
  </code></pre>