关闭

196. Delete Duplicate Emails

163人阅读 评论(0) 收藏 举报
分类:

Write a SQL query to delete all duplicate email entriesin 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 thistable.

For example,after running your query, the above Person tableshould have the following rows:

+----+------------------+

| Id | Email            |

+----+------------------+

| 1 | john@example.com |

| 2 | bob@example.com  |

+----+------------------+


DELETE a
FROM Person a, Person b
WHERE a.Id>b.Id AND a.Email=b.Email;




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:34682次
    • 积分:1432
    • 等级:
    • 排名:千里之外
    • 原创:116篇
    • 转载:2篇
    • 译文:0篇
    • 评论:1条
    文章分类
    最新评论