SQL 实现分页查询 select limit offset 总结

1、当limit后面跟一个参数的时候,该参数表示要取的数据的数量

select * from table limit 10; // 返回前10行
select * from table limit 20; // 返回前20行
select * from table limit 30; // 返回前30行

 

2、当limit后面跟两个参数的时候,第一个数表示要跳过的数量,后一位表示要取的数量

select * from table limit 0,20; //跳过前0条,读取20条
select * from table limit 20,20; //跳过前20条,读取20条
select * from table limit 40,20; //跳过前40条,读取20条

 

3、当limit和offset组合使用的时候,limit后面只能有一个参数,表示要取的的数量,offset表示要跳过的数量

select * from table limit 20 offset 0; //跳过前0条,读取20条
select * from table limit 20 offset 20; //跳过前20条,读取20条
select * from table limit 20 offset 40; //跳过前40条,读取20条

 

posted @ 2021-12-02 09:09  土豆核  阅读(1674)  评论(0编辑  收藏  举报