how to delete oldest mysql table records, but leave 1000 newest

mysql, sql

Solution

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`.

Problem

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.

Original source