Say I have records with IDs 3,4,7,9 and I want to be able to go from one to another by navitagion via next/previous links. The problem is, that I don't know how to fetch record with nearest higher ID.
So when I have record with ID 4, I need to be able to fetch next existing record, which would be 7. The query would probably look something like
SELECT * FROM foo WHERE id = 4 OFFSET 1
How can I fetch next/previous record without fetching whole result set and manualy iterating?
I'm using MySQL 5.