This has me completely stumped. From a set of numbers - for this example 1 to 20, I'm trying to do previous and next links, so they end up like this: I'll be supplying the number to start from.
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
n-5 p-6 n-10 p-11 n-15 p-16
Have you any idea how to do the sql for something like this?
I was trying to build on this one, but no luck:
SELECT c.id,
(SELECT MAX(p.id) FROM mytable p WHERE p.id < c.id AND p.country = 'us') prev_id,
(SELECT MIN(n.id) FROM mytable n WHERE n.id > c.id AND n.country = 'us') next_id
FROM mytable as c WHERE c.id = 5;
Table data
"id" "country"
"1" "US"
"2" "US"
"3" "US"
"4" "US"
"5" "US"
"6" "US"
"7" "US"
"8" "US"
"9" "US"
"10" "US"
"11" "US"
"12" "US"
Desired output
number provided by me = 10
prev | next
-------------
6 | 10
MyTable.IDs in4columns?