传统写法
limit 偏移量,取出条数
SELECT * FROM yundou_management.service_order where order_status=1 order by id asc limit 108,8 ;
mysql5之后支持新写法,让人更容易理解
limit 取出条数 offset 偏移量
SELECT * FROM yundou_management.service_order where order_status=1 order by id asc limit 8 offset 108 ;
假如从第一条开始获取指定条数量,偏移量为0
SELECT * FROM yundou_management.service_order where order_status=1 order by id asc limit 0,8 ;
SELECT * FROM yundou_management.service_order where order_status=1 order by id asc limit 8 offset 0 ;
也可以简写成如下
SELECT * FROM yundou_management.service_order where order_status=1 order by id asc limit 8;
随着偏移量越来越大,查询速度会越来越慢,解决方案在之前的文章已经介绍过。
原文地址:https://blog.51cto.com/phpme/2421747
时间: 2024-10-08 06:05:14