在LeetCode上遇见一道题目
delete from Person where id in (
SELECT P2.ID FROM Person P1 LEFT JOIN Person P2 on P1.Email = P2.Email AND P1.id < P2.id WHERE P2.ID is NOT null
);
大佬不要吐槽我太渣
然后爆出1093,才知道自己在删除的时候有查询影响了结果集
解决方案使用链接
delete p from Person p join (
SELECT P2.ID FROM Person P1 LEFT JOIN Person P2 on P1.Email = P2.Email AND P1.id < P2.id WHERE P2.ID is NOT null
) temp on p.id = temp.id;