mysql getting values from row using another item in the row code example
Example 1: get next/previous record
SELECT name,
(SELECT name FROM student s1
WHERE s1.id < s.id
ORDER BY id DESC LIMIT 1) as previous_name,
(SELECT name FROM student s2
WHERE s2.id > s.id
ORDER BY id ASC LIMIT 1) as next_name
FROM student s
WHERE id = 7;
Example 2: mysql query with sql to get the next row
SELECT * FROM foo WHERE id = (SELECT MIN(id) FROM foo WHERE id > 4)