STRUCTURE TABLES AND ERROR WHEN EXECUTE QUERY ON SQLFIDDLE
我有表News
。
例如,我得到NewsIdn = '164955'
:
SELECT * FROM News WHERE NewsIdn = '164955'
上一行有NewsIdn = '270085'
,下一行有NewsIdn = '324955'
。
请告诉我如何使用mysql查询获取上一个NewsIdn
和下一个NewsIdn
?
答案 0 :(得分:2)
也许是这样的:
SELECT * FROM News WHERE NewsIdn = '164955';
select * from News WHERE ID <
(select ID from News where NewsIdn = '164955') Order by ID DESC Limit 1;
select * from News WHERE ID >
(select ID from News where NewsIdn = '164955') Order by ID Limit 1;
答案 1 :(得分:0)
试试这个:
一个:
SELECT * FROM News WHERE NewsIdn < '164955' ORDER BY NewsIdn DESC LIMIT 1
下一步:
SELECT * FROM News WHERE NewsIdn > '164955' ORDER BY NewsIdn LIMIT 1