如果ID是主键或者有索引,可以直接查找:

方法一:

查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误):

select * from table_a where id = (select id from table_a where id < {$id} [and other_conditions] order by id desc limit 1) [and other_conditions];

查询下一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误):

select * from table_a where id = (select id from table_a where id > {$id} [and other_conditions] order by id asc limit 1) [and other_conditions];

方法二:

查询上一条记录的SQL语句((如果有其他的查询条件记得加上other_conditions以免出现不必要的错误))

select * from table_a where id = (select max(id) from table_a where id < {$id} [and other_conditions]) [and other_conditions];

查询下一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误):

select * from table_a where id = (select min(id) from table_a where id > {$id} [and other_conditions]) [and other_conditions];

最新文章

  1. 【Android自学日记】搭建Android开发环境
  2. ROS机器人语音交互(一)
  3. Console API 与命令行
  4. Ubuntu14.04安装redis和简单配置
  5. SRS用列建模
  6. Linux 多线程应用中如何编写安全的信号处理函数
  7. java初级开发中的报错问题
  8. android下拉选择框spinner
  9. DevExpress GridControl 显示行号、设置行号宽
  10. Memcahce(MC)系列(一)Memcache介绍、使用、存储、算法、优化
  11. 开源项目:底部动作条(BottomSheet)
  12. python网络编程之单线程之间的并发
  13. 我的2017年终总结(PF项目框架设计心得分享 1.0rc new)
  14. MySQL表的创建
  15. hello1以及hello2的部分代码分析
  16. java之异常统一处理
  17. jq demo—图片翻页展示效果 animate()动画
  18. CH4401 蒲公英
  19. OpenGL中摄像机矩阵的计算原理
  20. 【JS】一款好用的JS日历选择插件【bootstrap-datetimepicker.js】

热门文章

  1. 《JAVA设计模式》之组合模式(Composite)
  2. [CF960G]Bandit Blues(第一类斯特林数+分治卷积)
  3. bjsxt学习笔记:Dubbo
  4. deque(双向队列)基本用法
  5. 13、numpy——算术函数
  6. Codeforces - 1195D1 - Submarine in the Rybinsk Sea (easy edition) - 水题
  7. spark连接hive找不到table
  8. C# DATETIME格式转换汇总 根据日期获取星期
  9. 20191114PHP文件操作
  10. C#实现百度ping功能