Let’s say I have table with following columns:
- id
- created_at
The default sort on this table is “created_at DESC, id DESC”.
Then for example I want to query for 5 records newer than given date, but
newer means if there are 100 newer in total I want the 5 that are the oldest
in this group (are the closest to given date).
So the way I would do it is – I would change the sort to “created_at ASC, id ASC”
and then query for WHERE created_at > date LIMIT 5.
The problem is that I would like to return it in the default sort. I am thinking about
some subquery but I am not sure what would be the best solution. Any ideas?
Your though was good, enclose your query (as a subquery) in another one: