196. Delete Duplicate Emails

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;




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Chenyt01/article/details/52357267
个人分类: LeetCode MySQL
上一篇197. Rising Temperature
下一篇183. Customers Who Never Order
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭