MySQL分页limit的使用方法

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值