196. Delete Duplicate Emails

浅浅的花香味﹌ 2022-06-10 14:42 209阅读 0赞

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 |
+——+—————————+

# Write your MySQL query statement below
DELETE p FROM Person p,Person q where p.Id>q.Id AND q.Email=p.Email

发表评论

表情:
评论列表 (有 0 条评论,209人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Abap DELETE - duplicates

    今天发现自已一直忽视了一个问题, DELETE - duplicates 删除内表重复记录语句是有条件限制的,必需是依据关键字或你定义的字段排序后才行。 仔细看了一下它的文档