This is a question in Leetcode: https://leetcode.com/problems/delete-duplicate-emails/solution/
Basically the question asks to delete duplicate emails and keep the one that has the minumal index.
My code is the following one, and I firstly ran it in SQL Server mode, and it shows "Internal Error". But it has passed in MySQL mode. Why does this happen? Are there any syntax differences between them shown in this case? Thanks.
delete from Person
where Id not in (
select temp.minimum from
(select min(Id) as minimum from Person group by Email) as temp
);
Internal Erroryou got ?leetcodedoes a full self-join onemail, which could be quite clean. In MySQL 8/SQL Server, the CTE and ROW_Number will find the non-duplicates in a single pass. You'll have to compare exeuction plans for both queries (accepted and ROW_NUMBER) to find which is best