如果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. GridView获取当前行
  2. EF 学习笔记
  3. CRM 2016 自定义lookup过滤
  4. Unescape HTML entities in Javascript Unescape HTML转成html代码
  5. c语言里用结构体和指针函数实现面向对象思想
  6. scanf()常犯错误
  7. 10令人惊叹的模型的影响HTML5应用程序及源代码
  8. ExtJs--15--Ext.is*各种类型推断的方法,简单看源代码就能够明确了
  9. 练习半音阶口琴---&gt;&gt;修理推键所感
  10. nodeJS之域名DNS
  11. Linux下的crontab
  12. Vue 过滤器的使用
  13. min_25筛
  14. IBM MQ相关 ---- 系列文章
  15. 使用commons-pool2实现FTP连接池
  16. 第11月第21天 php引用 codeigniter cakephp
  17. Atcoder Grand Contest 010 C - Cleaning 树贪心(伪)
  18. python入门第0篇 Windows下python的安装及pip安装和使用
  19. Nodejs学习笔记(十一)—数据采集器示例(request和cheerio)
  20. WdColor&#160;枚举&#160;(Word)

热门文章

  1. Java体系总结
  2. 10个利用Eclipse调试Java的常见技巧
  3. [开源夏令营][四] Docker remote API 之 镜像篇
  4. [Typescript] Function defination
  5. SVN服务器的本地搭建和使用
  6. FileGeodatabase和PersonalGeodatabase与ArcSDEGeodatabase三种数据库比较.
  7. .Net HttpClient 模拟登录微信公众平台发送消息
  8. javaScript中将时间戳转换成日期格式
  9. PHP数组的排序函数
  10. 响应式Asp.net MVC企业网站源码