LeetCode 196:Delete Duplicate Emails
【Description】
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.
For example, after running your query, the above Person table should have the following rows:
Note:
Your output is the whole Person table after executing your sql. Use delete statement.
【Solution】
delete p1
from person p1, person p2
where p1.email=p2.email
and p1.id>p2.id
p1.id>p2.id
means that we delete the second one.