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

最佳答案

也许是这样的:

主要查询:

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;

10-08 09:48