我们在网站文章详情页经常看到,上一篇文章,下一篇文章,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