i have something like this:
DELETE FROM `history` WHERE `date_field` <= now() - INTERVAL 10 DAY
but if all records is older than 10 days - this query deletes all! i want to keep last 20 records, even if they too old !
Please help, what and how i need to upd my code, and what will be better use limit+offset of windowed function OVER() or need smth another ?
Join with a subquery that gets the most recent 20 days and excludes them.