查询文章的上一篇或下一篇的sql

1、查询当前的文章上一篇文章。 

// 查询上一篇文章

select * from article
where id =
(select id from
	article where id < ${id} 
	order by id desc limit 1
)

2、查询当前文章下一篇文章。

// 查询当前文章下一篇

select * from article
where id =
(select id from article
	where id > ${id}
	order by id asc limit 1
)

猜你喜欢

转载自blog.csdn.net/qq_31984879/article/details/84257893