SQL取上一条, 下一条记录方法

如果我们需要取id为3的前后的1条记录. 就可以用以下方法

取上一条记录:

1
select  *  from `表名` where `id`<3 order by `id` desc limit 1


取下一条记录:
1
select  *  from `表名` where `id`>3 order by `id` asc limit 1

大小于比较 + order + limit


SQL取上一条, 下一条记录方法
http://edk24.com/2016/d5184d65.html
作者
余小波
发布于
2016年1月19日
许可协议