MySQL数据库-数据的分页操作(limit) 命令演示

本文详细解析了SQL中使用LIMIT进行分页查询的方法,包括如何指定查询起始位置和数量,以及结合ORDER BY进行排序的技巧。通过实例展示了不同场景下的分页查询语句。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分页

limit start,count
  • 限制查询出来的数据格式
    select * from students where gender=1 limit 2;

  • 查询前5个数据
    select * from students limit 0,5;

  • 查询id6-10(包含)的书序
    select * from students limit 5,5;

  • 每页显示2个,第1个页面
    select * from students limit 0,2;

  • 每页显示2个,第2个页面
    select * from students limit 2,2;

  • 每页显示2个,第3个页面
    select * from students limit 4,2;

  • 每页显示2个,第4个页面
    select * from students limit 6,2; – -----> limit (第N页-1)*每页的个数, 每页的个数;

  • 每页显示2个,显示第6页的信息, 按照年龄从小到大排序
    select * from students order by age asc limit 10,2;
    select * from students where gender=2 order by age desc limit 0,2;
    失败select * from students limit 2*(6-1),2;
    失败select * from students limit 10,2 order by age asc;
    注:limit 需放在最后

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值