Delete Duplicate Emails

easy hash map database deduplication

Problem

Write a SQL statement to delete all duplicate emails from the Person table, keeping only the row with the smallest id for each duplicate email.

SQL: DELETE p1 FROM Person p1, Person p2 WHERE p1.email = p2.email AND p1.id > p2.id;

InputPerson = [(1,a@b),(2,c@d),(3,a@b)]
Output[(1,a@b),(2,c@d)]

DELETE p1 FROM Person p1, Person p2
WHERE p1.email = p2.email AND p1.id > p2.id;
Time: O(n) Space: O(n)