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. 基于DCT系数的实时监控中运动目标检测

    本文的主要内容来自2009 Advanced Video and Signal Based Surveillance会议的一篇论文“Real-Time Moving Object Detection ...

  2. HDU4738:Caocao's Bridges(求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 使用自己的数据集训练和测试"caffenet"

    主要步骤可参考: http://blog.csdn.net/u010194274/article/details/50575284 补充几点: 1. convert函数是ImageMagick包里面的 ...

  4. HDU3336 KMP+DP

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. spring boot 在IDEA控制台中打印彩色日志

    只需要在application.properties中加入 spring.output.ansi.enabled=ALWAYS 即可

  6. 51Nod 1062 序列中最大的数 | 简单DP

    #include "iostream" #include "cstdio" using namespace std; #define LL long long ...

  7. 数据结构:ST表

    BZOJ1699 在经历了树套树和主席树的洗礼之后,所有的数据结构都显得格外地亲切,和自然.. ST算法能够实现O(nlogn)的预处理的情况下完成O(1)的区间最值查询 虽然这要求区间是静态的,也就 ...

  8. MySQL和Postgresql的区别

    一.PostgreSQL相对于MySQL的优势 1.在SQL的标准实现上要比MySQL完善,而且功能实现比较严谨:2.存储过程的功能支持要比MySQL好,具备本地缓存执行计划的能力:3.对表连接支持较 ...

  9. HDU 1574 RP问题 (dp)

    题目链接 Problem Description 在人类社会中,任何个体都具有人品,人品有各种不同的形式,可以从一种形式转换为另一种形式,从一个个体传递给另一个个体,在转换和传递的过程中,人品不会消失 ...

  10. bzoj 1588 bst

    用set存下就好了. /************************************************************** Problem: 1588 User: BLADE ...