select
content, country_id,
(select title from information WHERE #{id} > id and (status = 1) ORDER BY id DESC limit 1) AS last_title,
(select title from information WHERE id > #{id} and (status = 1) ORDER BY id limit 1) AS next_title,
picture, status, timestamp, title, type
from information
where id = #{id} and status = 1
提醒:
结尾不加 “;”
无需注意大小写
不要使用小于号
尽管一个查询方便快捷,但还是推荐拆开查询,便于代码后期的维护和需求的变更。
比如查询这个字段的上一个字段:
select title as last_title from information WHERE #{id} > id and (status = 1) ORDER BY id DESC limit 1
比如查询这个字段的下一个字段:
select title as next_title from information WHERE id > #{id} and (status = 1) ORDER BY id limit 1