leetcode.196. Delete Duplicate Emails
2016-07-11 12:05
393 查看
Write a SQL query to delete all duplicate email entries in a table named
only unique emails based on its smallest Id.
For example, after running your query, the above
rows:
# Write your MySQL query statement below
DELETE FROM Person
WHERE Id NOT IN (SELECT TMP.MIN_ID
FROM (SELECT MIN(ID) MIN_ID
FROM Person
GROUP BY Email) TMP);
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 | +----+------------------+
# Write your MySQL query statement below
DELETE FROM Person
WHERE Id NOT IN (SELECT TMP.MIN_ID
FROM (SELECT MIN(ID) MIN_ID
FROM Person
GROUP BY Email) TMP);
相关文章推荐
- codeforces C3. Brain Network (hard) (lca,树的直径)
- web.xml is missing and <failOnMissingWebXml> is se
- leetcode.182. Duplicate Emails
- C2. Brain Network (medium)
- HBase长时间无法关闭问题及处理(Waiting on regionserver(s) to go down)
- POJ1273Drainage Ditches
- Genymotion模拟器出现Unable to create virtual device Fail to create SD card解决方法
- See You Again--Wiz Khalifa
- ssh client 报 algorithm negotiation failed
- 70. Climbing Stairs
- Thread_wait、notify、notifyAll的使用方法
- AIX 常用命令
- 【POJ3691】 DNA repair (AC自动机+DP)
- AFNetworking Error Domain=NSCocoaErrorDomain Code=3840
- rails render partial的问题(collection)
- Codeforces 690C2 Brain Network (medium) (树的直径)
- HDU 4251 The Famous ICPC Team Again 划分树 区间第K大
- http://blog.csdn.net/liuzhenwen/article/details/4155447
- jenkins集成ansible注意事项Failed to connect to the host via ssh.
- POJ 1273 Drainage Ditches(最大流模板)