如何删除最旧的mysql表记录,但最新留下1000

Pro*_*tor 3 mysql sql

什么查询删除最旧的mysql表记录,但保留1000最新.记录的记录并不重要 - 我需要1000个最新记录.

jue*_*n d 8

delete from your_table
where id not in
(
   select * from 
   (
      select id from your_table
      order by id desc
      limit 1000
   ) x
)
Run Code Online (Sandbox Code Playgroud)

内部select返回最近的1000个ID.另一个delete删除所有记录,但内部记录select.