196. Delete Duplicate Emails
2024-10-19 22:28:48
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
);
最新文章
- 冒泡排序java代码
- JS添加MD5,JS提示框
- doctrine2到底是个什么玩意
- PB小技巧集锦
- Cakephp 创建无模型的Controller
- HDOJ 1272 并查集 不相同父节点
- SQL2005性能分析一些细节功能你是否有用到?(二)
- mysql数据库 触发器简单实例
- Java实现二叉树先序,中序,后序遍历
- 使用千位分隔符(逗号)表示web网页中的大数字
- c# Socket通讯中关于粘包,半包的处理,加分割符
- ref、out参数
- cmd切换目录
- oracle 中查看数据库表中某个字段是否重复
- Jpush极光推送的一些心得
- Luogu P2482 [SDOI2010]猪国杀
- hashCode方法的作用?
- EF Code First MySql 主从表设计的一些需要注意的内容
- 【CF932G】Palindrome Partition 回文自动机
- sql中 设置区分大小写
热门文章
- shell中的$* $@
- AndroidManifest Ambiguity方案原理及代码
- Getting Private/Public IP address of EC2 instance using AWS-cli [closed]
- Java集合(3)一 红黑树、TreeMap与TreeSet(上)
- vijos 1448 校门外的树 树状数组
- python3 mysql 时间参数错误
- Strand Sort
- urllib3使用指南
- promise 如何知道所有的回调都执行完了?
- 日常开发技巧:在远程机器上直接使用adb