SQL sort with limit? (non trivial)
table {
id: long
name: string
}
1235 Fred
1902 Trever
5123 George
6467 Derek
7868 Joe
8972 Bob
9272 Alf
9842 Hank
I want to return 2 records prior to that of Joes, in ascending order.
i.e The correct values should be:
5123 George
6467 Derek
I have tried
- Returns incorrect rows:
select * from table with id<7868 order by id asc limit 2
- Returns incorrect sort order:
select * from table with id<7868 order by id desc limit 2