What query deletes oldest mysql table records, but leave 1000 newest. does not matter how mush records are there - I need 1000 newest of them.
delete from your_table
where id not in
(
select * from
(
select id from your_table
order by id desc
limit 1000
) x
)
The inner select returns the most recent 1000 ids. The other delete deletes all records but the ones from the inner select.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With