I have some query on a table which can be sorted by any of several columns, and an id of a row in the resultset. How can I get the next or previous records (or the offset of the id in the complete resultset).
ie. let's say I have the following table
ID First_Col Second_Col Name
1 34 24 John
2 40 22 James
3 48 5 Hugh
If sorting by first_col, and given id 2, the next record would be 3, but if sorting by Second_Col, the next record would be 1.
Given the sortBy expression (which is passed to my function), and the id, how can I find the next record easily?