Amiya Sahu Web Developer

Get Next or Previous record in MySQL

Query to get Next record in MySQL

SELECT * FROM foo WHERE id = (SELECT MIN(id) FROM foo WHERE id > 4)

Query to get Previous record in MySQL

SELECT * FROM foo WHERE id = (SELECT MAX(id) FROM foo WHERE id < 4)