sql查询上一条记录和下一条记录

时间:2023-03-08 19:18:20
上一条记录的SQL语句:

select top 1 * from news where newsid<id order by newsid DESC

下一条记录的SQL语句:

select top 1 * from news where newsid>id order by newsid ASC

开发中遇到需要在当前页面显示当前文章的上一篇文章和下一篇文章,百度了一下,搜索到以上SQL语句: