sql语句查询某条数据的上一条和下一条数据

表searchId为当前id

1.查询上一条数据

select * from tbContent where id=(select max(id) from tbContent where id<searchId) 

2.查询下一条数据

select * from tbContent  where id=(select min(id) from tbContent  where id>searchId)

3.查询上一条和下一条数据

select * from tbContent where 
id in((select max(id) from tbContent where id< searchId), 
(select min(id) from tbContent where id> searchId)) 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章