LeetCode - Delete Duplicate Emails

   Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.

   删除重复的Email地址,保留Id最小的那个。

   使用自身连接循环即可。

 

# Write your MySQL query statement below
delete p1 from Person p1, Person p2
where p1.Email=p2.Email and p1.Id>p2.Id;

 

posted @ 2015-04-19 22:16  Pickle  阅读(191)  评论(0编辑  收藏  举报