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

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


取上一条记录:

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


取下一条记录:

select  *  from `表名` where `id`>3 order by `id` asc limit 1



大小于比较 + order + limit 


posted @ 2016-01-19 05:17  余晓波  阅读(607)  评论(0编辑  收藏  举报