MySQL中根据ID查询指定记录(id为26)的上一条记录和下一条记录:
上一条 SELECT * FROM xxx WHERE id < 26 ORDER BY id DESC LIMIT 1;
下一条 SELECT * FROM xxx WHERE id > 26 ORDER BY id LIMIT 1;
或者试试:
上一条
select * from xxx where id =
(select max(id) from xxxx where id < 26 order by px_id desc, id desc);
下一条
select * from content where id =
(select min(id) from xxxx where id > 26 order by px_id desc, id desc);