I have a database with up to some n entries allowed. Periodically, it needs to be trimmed down to the most recent m entries.
The table (call it mytable
) has a datetime stamp runstamp
My general thought was to run a query like this
delete from mytable where runstamp <
(select min(runstamp) from mytable order by runstamp limit m)
But it turns out that the max is taken before the limit is applied, and I'm not sure how to get the job done now.
Implementation detail that may not matter: this is being done in sqlite.