MySQL分页limit的使用方法

来源:互联网 发布:盐城办公软件培训 编辑:程序博客网 时间:2024/05/18 03:31
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 0
原创粉丝点击