Delete Duplicate Emails:SQL删除重复邮件地址
2018-01-15 12:51
537 查看
Write a SQL query to delete all duplicate email entries in a table named
based on its smallest Id.
For example, after running your query, the above
思路:
delete p1 from Person p1,Person p2
where p1.Email = p2.Email and p1.Id > p2.Id
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 | +----+------------------+
思路:
delete p1 from Person p1,Person p2
where p1.Email = p2.Email and p1.Id > p2.Id
相关文章推荐
- leetcode | Delete Duplicate Emails | 删除表中重复项
- [LeetCode] Delete Duplicate Emails 删除重复邮箱
- SQL Server使用触发器删除重复的列(Delete duplicate rows using cursor in SQL Server)
- leetcode196-Delete Duplicate Emails(删除重复并且id较大的数据)
- SQL-Delete Duplicate Emails
- leetcode【sql】 Delete Duplicate Emails
- 使用DELETE ADJACENT DUPLICATES FROM 删除内表邻近重复记录需要注意事项
- SQL-Delete Duplicate Emails
- leetcode数据库sql之Delete Duplicate Emails
- [LeetCode] Insert Delete GetRandom O(1) - Duplicates allowed 常数时间内插入删除和获得随机数 - 允许重复
- 【转】排序删除重复行delete adjacent duplicates from
- [LeetCode][SQL]Delete Duplicate Emails
- sql 删除重复记录
- 查询并删除重复记录的SQL语句
- 一条删除部分字段重复的SQL命令
- SQL删除重复数据只保留一条
- 删除oracle 表中重复数据sql语句、保留rowid最小的一条记录
- SQL查找删除重复行
- 删除一个表中的重复数据同时保留第一次插入那一条以及sql优化
- MS-SQL删除数据库中的重复行