SQL查询语句中的 limit 与 offset 的区别

SQL查询语句中的 limit 与 offset 的区别:

  • limit y 分句表示: 读取 y 条数据

  • limit x, y 分句表示: 跳过 x 条数据,读取 y 条数据

  • limit y offset x 分句表示: 跳过 x 条数据,读取 y 条数据

比如分页获取数据:

第1页: 从第0个开始,获取20条数据

select * from testtable limit 0, 20; 
select * from testtable limit 20 offset 0;  

第2页: 从第20个开始,获取20条数据

select * from testtable limit 20, 20; 
select * from testtable limit 20 offset 20;  

第3页: 从第40个开始,获取20条数据

select * from testtable limit 40, 20;  
select * from testtable limit 20 offset 40;   

[END]

posted @ 2020-08-02 15:38  澈念明通  阅读(273)  评论(0)    收藏  举报