Write a SQL query to delete all duplicate email entries in a table named 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 Person table should have the following rows:

+----+------------------+
| Id | Email |
+----+------------------+
| 1 | john@example.com |
| 2 | bob@example.com |
+----+------------------+ 删除重复的地址,保留ID最小的 MySQL(714ms):
DELETE FROM Person
WHERE Id NOT IN (
SELECT * FROM(
SELECT MIN(Id)
FROM Person
GROUP BY Email
) AS Mid
);

最新文章

  1. 冒泡排序java代码
  2. JS添加MD5,JS提示框
  3. doctrine2到底是个什么玩意
  4. PB小技巧集锦
  5. Cakephp 创建无模型的Controller
  6. HDOJ 1272 并查集 不相同父节点
  7. SQL2005性能分析一些细节功能你是否有用到?(二)
  8. mysql数据库 触发器简单实例
  9. Java实现二叉树先序,中序,后序遍历
  10. 使用千位分隔符(逗号)表示web网页中的大数字
  11. c# Socket通讯中关于粘包,半包的处理,加分割符
  12. ref、out参数
  13. cmd切换目录
  14. oracle 中查看数据库表中某个字段是否重复
  15. Jpush极光推送的一些心得
  16. Luogu P2482 [SDOI2010]猪国杀
  17. hashCode方法的作用?
  18. EF Code First MySql 主从表设计的一些需要注意的内容
  19. 【CF932G】Palindrome Partition 回文自动机
  20. sql中 设置区分大小写

热门文章

  1. shell中的$* $@
  2. AndroidManifest Ambiguity方案原理及代码
  3. Getting Private/Public IP address of EC2 instance using AWS-cli [closed]
  4. Java集合(3)一 红黑树、TreeMap与TreeSet(上)
  5. vijos 1448 校门外的树 树状数组
  6. python3 mysql 时间参数错误
  7. Strand Sort
  8. urllib3使用指南
  9. promise 如何知道所有的回调都执行完了?
  10. 日常开发技巧:在远程机器上直接使用adb