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)) 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章