Mysql 上一篇 下一篇语句

网站文章详情页常需显示上一篇和下一篇文章,本文提供两种Mysql语句写法。一是用max()、min()函数,二是用order by desc(asc) limit,还给出了如查询第二十五篇博客上下篇的具体示例。

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

我们在网站文章详情页经常看到,上一篇文章,下一篇文章,Mysql语句怎么写呢?下面提供两种语句的写法。

例如:第二十五篇博客的,上一篇和下一篇

第一种:使用max() 、min()函数

上一篇:select id,title from attic_blog where id = (select max(id) as id from attic_blog  where id<25);

下一篇:select id,title from attic_blog where id = (select min(id) as id from attic_blog  where id>25);

第二种方法使用order by  desc(asc) limit:

上一篇:select id,title from attic_blog where id<25 order by id desc  limit 1

下一篇:select id,title from attic_blog where id>25 order by id asc  limit 1

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值