27
SELECT name FROM mydb ORDER BY score DESC LIMIT 10;

The query above will return the first 10 ranks.

How to modify the LIMIT, or maybe is there another syntax to query the 10th rank through the 20th rank?

informatik01
  • 16,038
  • 10
  • 74
  • 104
theHack
  • 1,938
  • 9
  • 26
  • 33

5 Answers5

65

You should use:

SELECT name FROM mydb ORDER BY score DESC LIMIT 10,10;

http://dev.mysql.com/doc/refman/5.5/en/select.html

The two arguments 10,10 are (Offset, Limit) so this will retrieve rows 11-20.
9,11 Would be required to grab the 10th - 20th rank.

StarSweeper
  • 397
  • 2
  • 4
  • 28
James C
  • 14,047
  • 1
  • 34
  • 43
24

Use offset to clarify the query.

SELECT name FROM mydb ORDER BY score DESC LIMIT 10 OFFSET 10
jotapdiez
  • 1,456
  • 13
  • 28
6

Limit has also an offset parameter

SELECT name FROM mydb ORDER BY score DESC LIMIT 10,10
Nicola Cossu
  • 54,599
  • 15
  • 92
  • 98
1

you may use offset

SELECT name FROM mydb ORDER BY score DESC LIMIT 10 OFFSET 10

here, offset indicates that from where next 10 data will show.

you may also use below :

SELECT name FROM mydb ORDER BY score DESC LIMIT 10, 10
  • 3
    Please [don't provide a solution that is already covered by another answer](//meta.stackexchange.com/a/192293/269535). If you agree with another answer, then when you have enough [reputation](//stackoverflow.com/help/whats-reputation) you may [upvote it](//stackoverflow.com/privileges/vote-up), which is the Stack Overflow way of indicating your agreement. See also [answer]. – Scott Weldon Oct 20 '16 at 03:08
1
SET @rank = 0;
SELECT rank, name, score
FROM (
    SELECT @rank := @rank +1 AS rank, name, score
    FROM mydb
    ORDER BY score DESC 
    LIMIT 100 
) X
WHERE rank >= 10;
Farvardin
  • 5,336
  • 5
  • 33
  • 54
Christo
  • 8,729
  • 2
  • 22
  • 16