[LeetCode]-DataBase-Delete Duplicate Emails
2016-03-21 18:33
162 查看
Write a SQL query to delete all duplicate email entries in a table named
For example, after running your query, the above
DELETE t1 FROM persons t1 LEFT JOIN(
SELECT MIN(Id) Id,Email FROM Persons GROUP BY Email HAVING COUNT(Email)>1
)t2 ON t1.Email=t2.Email
WHERE t1.Id>t2.Id
Person, keeping only unique emails based on its smallest Id.
+----+------------------+ | Id | Email | +----+------------------+ | 1 | john@example.com | | 2 | bob@example.com | | 3 | john@example.com | +----+------------------+ Id is the primary key column for this table.
For example, after running your query, the above
Persontable should have the following rows:
+----+------------------+ | Id | Email | +----+------------------+ | 1 | john@example.com | | 2 | bob@example.com | +----+------------------+ 需求:删除重复数据,保留ID最小的
DELETE t1 FROM persons t1 LEFT JOIN(
SELECT MIN(Id) Id,Email FROM Persons GROUP BY Email HAVING COUNT(Email)>1
)t2 ON t1.Email=t2.Email
WHERE t1.Id>t2.Id
相关文章推荐
- strong,weak,assign,retain,copy区别与联系
- [LeetCode]-DataBase-Duplicate Emails
- async & await 的前世今生
- async 和 await 的异步处理
- Traits技术初探
- 循环 retain 问题
- 事务配置不对导致:•Could not obtain transaction-synchronized Session for current thread
- lightoj 1038-Race to 1 Again 期望类DP
- [LeetCode][智力题]Climbing Stairs
- 说说我们的通用型人工智能
- CLAIMS 第三方安装包编译问题
- 数据挖掘十大经典算法(九) 朴素贝叶斯分类器 Naive Bayes
- FOJ-1001-Duplicate Pair
- IntelliJ IDEA 工具grails实现多个文件压缩下载
- Pair RDD基本操作
- main函数第3个参数envp装的是什么
- 217. Contains Duplicate
- inotifywait
- IntelliJ IDEA 工具grails框架打war包
- baiduAPI 免费调用天气预报