删除不是最近的所有内容

时间:2014-03-25 14:49:14

标签: mysql sql

看看这个并试试我的帮助,

由于

DELETE FROM table WHERE id < ((SELECT count(*) FROM table) - 10);

1 个答案:

答案 0 :(得分:1)

要从表中删除除最后10行之外的所有行:

delete from mytable
where id < (select min(id) from (
  select id
  from mytable
  order by id desc
  limit 10) x)

请参阅SQLFiddle