I'm using MariaDB and would like to purge records periodically from my database leaving only the last record in the DB per day, so over 7 days there would be only 7 records remaining.
I've found something similar to what I want to do here.
DELETE FROM `table` WHERE id NOT IN ( SELECT id FROM (
SELECT id
FROM `table`
ORDER BY id DESC
LIMIT 1 ) foo );
This deletes all but the last record but I would like something which will leave the last record each day so I have the latest entry daily. The solution doesn't have to iterate back through the days, I can run this every day at say midnight to process the day before.
I have a column called 'stamp' which is a timestamp column.