SQL sort with limit? (non trivial)
17:02 25 May 2009
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

  1. Returns incorrect rows:

select * from table with id<7868 order by id asc limit 2

  1. Returns incorrect sort order:

select * from table with id<7868 order by id desc limit 2

java sql