sql easy
delete from person where id not in(select * from(select MIN(id) from person group by email) t);
这道题, 涉及到一个很重要的知识点:
如果我们直接筛选 id 然后删除:
delete from personwhere id not in(select MIN(id) from person group by email);
会报错: You can't specify target table 'person' for update in FROM clause. 这个错误的意思是不能在同一个 sql 语句中, 先 select 同一个表的某些值, 然后再 update 这个表.
解决方法: select 的结果再通过一个中间表 select 多一次, 就可以避免这个错误. 目前遇到 update 也会这样,其他的 DML 语句后续遇到了再补充.
