码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode - Delete Duplicate Emails

时间:2015-04-19 22:37:26      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:

   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;

 

LeetCode - Delete Duplicate Emails

标签:

原文地址:http://www.cnblogs.com/wxisme/p/4440175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!