I know can select the next or previous X records with statements like the following:
Next: `SELECT * FROM table WHERE some_key > 3 ORDER BY some_key ASC LIMIT X`
Previous: `SELECT * FROM table WHERE some_key < 3 ORDER BY some_key DESC LIMIT X`
However I’m working in a language which returns a Cursor over the results and I’d like all of my results in one cursor.
Is it possible to select the current record, along with X next and previous records in a single SQL statement?
In the end I used the answer from @mu, with some modifications
In Android, you cannot use inner
ORDER BYstatements in aUNION, just a single outerORDER BYon the whole set. To get around this I used the fact that SQLite on Android does support inner queries, performed each actual select in an inner query and then selected all rows from the inner query to union, as follows: