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
);

196. Delete Duplicate Emails的更多相关文章

  1. [SQL]196. Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  2. leetcode 196. Delete Duplicate Emails

    # 慢,内连接delete p1 from Person p1, Person p2 where p1.Email=p2.Email and p1.Id>p2.Id delete from Pe ...

  3. leetcode 196. Delete Duplicate Emails 配合查询的delete

    https://leetcode.com/problems/delete-duplicate-emails/description/ 题意要对原来的数据表进行删除,不删除不行,它每次只输出原来那个表. ...

  4. LeetCode 196. Delete Duplicate Emails (删除重复的电子邮箱)

    题目标签: 题目给了我们一个 email 的表格,让我们删除重复的. 建立Person p1,Person p2,当email 相同时,而且 p1 id 要大于 p2 id 时候,删除这一行. Jav ...

  5. [LeetCode] Delete Duplicate Emails 删除重复邮箱

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  6. LeetCode Database: Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  7. leetcode【sql】 Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  8. [SQL]LeetCode196. 删除重复的电子邮箱 | Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  9. LeetCode DB : Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

随机推荐

  1. 洛谷:P3809 【模板】后缀排序(后缀数组模板)

    P3809 [模板]后缀排序 题目链接:https://www.luogu.org/problemnew/show/P3809 题目背景 这是一道模板题. 题目描述 读入一个长度为 nn 的由大小写英 ...

  2. Android IntentService分析

    IntentService其实是一个很通用的知识点,最近看了下阿里巴巴Android开发手册,再次记录下 阿里巴巴Android开发手册 [强制]避免在 BroadcastReceiver#onRec ...

  3. 牛客326B 背单词

    传送门:https://ac.nowcoder.com/acm/contest/326/B 题意:给你一个n,你需有找有多少个长度从1~n 的单词,满足最长连续元音少于A个并且最长连续辅音长度少于B. ...

  4. 转ajax的jsonp的文章

    转:http://justcoding.iteye.com/blog/1366102/ Js是不能跨域请求.出于安全考虑,js设计时不可以跨域. 什么是跨域: 1.域名不同时. 2.域名相同,端口不同 ...

  5. 团队题目需求分析-NABCD

    Need: 由本人亲身体验出发,觉得很多同学记不住老师留的作业,或者上课时间记录了,但是老是忘记到底记录了什么,导致没有半大写作业,所以准备设计一个东西来帮助同学. A: 首先,我最先想到的是手机,所 ...

  6. maven报错 Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.5.0 from

    maven报错误,类似于: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.5.0 from http ...

  7. 任务调度 Quartz 学习(三) CronTrigger 表达式

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表. CronT ...

  8. kafka命令总结

    ./kafka-console-consumer.sh  --bootstrap-server IP:9092  --topic user-asset-change-v1 --partition 2  ...

  9. Python随机选择Maya场景元素

    之前在公司参与的一个与国外合作的项目中,有一景需要动态.随机地选取场景中的一些物体,同时显示指定材质,当时是用Houdini的节点+Hscript 解决的: 今天用简洁优雅的Python在Maya中写 ...

  10. iOS-Apple苹果iPhone开发公开API

      iOS-Apple苹果iPhone开发 //技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilo ...