SQL取上一条, 下一条记录方法
阅读原文时间:2023年09月07日阅读:1

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

取上一条记录:

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

取下一条记录:

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

大小于比较 + order + limit