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

思路:
(1)首先说一下inner join(等价于join),以及他的衍生品left/right join。他们的实质就是在笛卡尔积的基础上加上了附加的条件
(2)然后就是delete的格式:
delete from table where..

delete
from p1
using Person p1 inner join Person p2
on p1.Id > p2.Id and p1.Email = p2.Email

SQL-Delete Duplicate Emails的更多相关文章

  1. [LeetCode] Delete Duplicate Emails 删除重复邮箱

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  2. leetcode【sql】 Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  3. [SQL]LeetCode196. 删除重复的电子邮箱 | Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  4. [SQL]196. Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  5. LeetCode Database: Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  6. LeetCode DB : Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  7. LeetCode - Delete Duplicate Emails

    Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping ...

  8. 196. Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  9. LeetCode——Delete Duplicate Emails(巧用mysql临时表)

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  10. sql leetcode -Duplicate Emails

    第一种解法: select distinct p1.Email as Email from Person p1, Person p2 where p1.Email=p2.Email and p1.Id ...

随机推荐

  1. Android开发之扫描附近wifi热点并列表显示

    近期项目中用到了wifi模块.今天做一个简单的总结. 參考:http://www.2cto.com/kf/201310/253617.html 1.如何获取wifi对象并进行操作 要操作WIFI设备, ...

  2. MySQL(14):Select-limit(限制获得的记录数量)

    1. limit 限制获得记录的数量 2.limit 语法: (1) limit  offset, row_count: offset偏移量,从0开始. row_count总记录数. 分析: 案例演示 ...

  3. MySQL(12):windows下解决mysql忘记密码

    mysql有时候忘记密码了怎么办?我给出案例和说明!一下就解决了!    Windows下的实际操作如下 : 1. 关闭正在运行的MySQL.  2. 打开DOS窗口,转到mysql\bin目录. 3 ...

  4. linux常见设备类型及文件系统

    As you can see in  Table   14.3   , all disk device names end with the letter a. That is because it ...

  5. (转)jquery的html,text,val

    .html()用为读取和修改元素的HTML标签 .text()用来读取或修改元素的纯文本内容 .val()用来读取或修改表单元素的value值. 这三个方法功能上的对比 .html(),.text() ...

  6. Entity Framework 的枚举类型

    新增数据模型,新增“实体”之后,新增“枚举类型”,创建Enum值,将“实体”中的列和Enum关联,选中“实体”中的列属性改变类型为Enum名称,生成数据库…… 如下转自:http://item.con ...

  7. Delphi 做ActiveX的详细过程

    1.新建 如下图 点击OK 依然点击OK 出现了如上图的节面,就像窗体一样. 然后 你就想干什么干什么. 这个做好之后, 这个是我设计的窗体. 然后 就添加 外部可以调用的接口了. 如果你不想让外部调 ...

  8. PHP Filesystem

    Runtime 配置 Filesystem 函数的行为受到 php.ini 中设置的影响. Filesystem 配置选项: 名称 默认 描述 可改变 allow_url_fopen "1& ...

  9. js回网页顶部

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. BIOS+MBR模式 VS UEFI+GPT模式

     EFI与MBR启动的区别 大硬盘和WIN8系统,让我们从传统的BIOS+MBR模式升级到UEFI+GPT模式,现在购买的主流电脑,都是预装WIN8系统,为了更好的支持2TB硬盘 ,更快速的启动win ...