get next previous id code example Example: mysql query with sql to get the next row SELECT * FROM foo WHERE id = (SELECT MIN(id) FROM foo WHERE id > 4)