MySQL中根據(jù)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);