I use both MySQL 4 and 5, so idealy the solution should work in both.
I have table_A which contains an primary index, value and average.
TABLE_A
ID|VALUE|AVERAGE
table_B links table_A to a category so that TABLE_A.ID=TABLE_B.AID
TABLE_B
AID|CID
I can create a list easily like so:
select * from TABLE_A
inner join TABLE_B on (TABLE_A.ID=TABLE_B.AID )
order by AVERAGE DESC
How do I get the next and previous ID when viewing just one ID?
I've done a query which displays just ID 20 with AVERAGE 3.44 but I want to know the next ID which has a AVERAGE higher then 3.44 and the previous ID which is lower.
select * from TABLE_A
inner join TABLE_B on (TABLE_A.ID=TABLE_B.AID )
where ID=20
Start Free Trial