Reputation:
STRUCTURE TABLES AND ERROR WHEN EXECUTE QUERY ON SQLFIDDLE
I have table News
.
For example i get row where NewsIdn = '164955'
:
SELECT * FROM News WHERE NewsIdn = '164955'
Previous row have NewsIdn = '270085'
and next row have NewsIdn = '324955'
.
Tell me please how get previous NewsIdn
and next NewsIdn
with help mysql query?
Upvotes: 0
Views: 147
Reputation: 3846
Maybe something like this:
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;
Upvotes: 2
Reputation: 1400
Try this:
Previous:
SELECT * FROM News WHERE NewsIdn < '164955' ORDER BY NewsIdn DESC LIMIT 1
Next:
SELECT * FROM News WHERE NewsIdn > '164955' ORDER BY NewsIdn LIMIT 1
Upvotes: 0