MySQL limit range

我只是一个虾纸丫 提交于 2019-11-27 22:49:36
James C

This is really basic stuff. 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.

Use offset to clarify the query.

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

Limit has also an offset parameter

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

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
Christo
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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!