您的位置:首页 > 数据库 > MySQL

MySQL分页limit的使用方法

2015-08-29 18:54 603 查看
select * from table limit 0,10

上面句子中,0是起始offset,10是select出来的record数目,整句的意思是,选择table中前十条

当然也可以直接写成

select * from table limit 10

如果换个offset
select * from table limit 5,10

这句的意思是,返回第6至15行record,虽然语句中第一个参数写的是5,但是实际上,是从offset+1开始,也就是6,所以是第6行开始,包括第六行,总共10条,也就是去到第15条record

如果table数目特别多,需要跳转到后面第几十页的话,例如下面这个例子,每页20个,查看第501页

select * from table where id>=10000 order by id asc limit 0,20

前1页
select * from table where id < 10000 order by id asc limit 0,20

前2页
select * from table where id < 10000 order by id asc limit 20,20

后1页

select * from table where id >= 10000 order by id asc limit 20,20
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: