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

Note:

Your output is the whole Person table after executing your sql. Use delete statement.

Code

DELETE p2 FROM Person AS p1, Person As p2 WHERE p1.Email = p2.Email AND p1.Id < p2.Id

[LeetCode] 196. Delete Duplicate Emails_Easy tag: SQL的更多相关文章

  1. [LeetCode] 182. Duplicate Emails_Easy tag: SQL

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  2. leetcode 196. Delete Duplicate Emails 配合查询的delete

    https://leetcode.com/problems/delete-duplicate-emails/description/ 题意要对原来的数据表进行删除,不删除不行,它每次只输出原来那个表. ...

  3. LeetCode 196. Delete Duplicate Emails (删除重复的电子邮箱)

    题目标签: 题目给了我们一个 email 的表格,让我们删除重复的. 建立Person p1,Person p2,当email 相同时,而且 p1 id 要大于 p2 id 时候,删除这一行. Jav ...

  4. leetcode 196. Delete Duplicate Emails

    # 慢,内连接delete p1 from Person p1, Person p2 where p1.Email=p2.Email and p1.Id>p2.Id delete from Pe ...

  5. [SQL]196. Delete Duplicate Emails

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

  6. LeetCode Database: Delete Duplicate Emails

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

  7. LeetCode DB : Delete Duplicate Emails

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

  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] 619. Biggest Single Number_Easy tag: SQL

    Table number contains many numbers in column num including duplicated ones.Can you write a SQL query ...

随机推荐

  1. Sencha Touch 实战开发培训 视频教程 第二期 第三节

    2014.4.11晚上8:10分开课. 本节课耗时一小时以上. 本期培训一共八节,前两节免费,后面的课程需要付费才可以观看. 本节内容:             本地储存.扩展按钮控件.微博分享 实现 ...

  2. 【BZOJ1478】Sgu282 Isomorphism Pólya定理神题

    [BZOJ1478]Sgu282 Isomorphism 题意:用$m$种颜色去染一张$n$个点的完全图,如果一个图可以通过节点重新标号变成另外一个图,则称这两个图是相同的.问不同的染色方案数.答案对 ...

  3. nose测试中修改nose_html_reporting插件,使生成的html报告加入显示截图功能

    使用nose框架在测试WEB UI自动化时,使用了第三方插件nose-html-reporting,来生成HTML报告,nose-html-reporting具体使用参见管网https://pypi. ...

  4. Unity3D笔记 英保通四 虚拟轴应用及键盘事件

    Input: 1.使用这个类能够读取输入管理器设置的按键,以及访问移动设备的多点触控或加速感应数据.想要读取轴向使用Input.GetAxis方法获取下列默认轴: "Horizontal&q ...

  5. vue--父子组件的传值

    什么是父子组件? 组件中引入组件,被引入的组件就是子组件.例如在 Hello.vue 组件中引入 Header.vue 组件,那么 Hello.vue 就是父组件,Header.vue就是子组件. 一 ...

  6. 洛谷P2698 花盆Flowerpot【单调队列】

    题目描述 Farmer John has been having trouble making his plants grow, and needs your help to water them p ...

  7. 洛谷P2414 阿狸的打字机【AC自动机】【fail树】【dfs序】【树状数组】

    居然真的遇上了这种蔡队题.瑟瑟发抖. 题目背景 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机. 题目描述 打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母.经阿 ...

  8. php.exe

    PhpStorm 10.0.2 php  interpreter  填入php.exe 暂且不用填写 Listen 63342

  9. memory addresses

    php.net References in PHP are a means to access the same variable content    by different names. The ...

  10. mysql主从服务器的配置

    使用mysql主从复制的好处有: 1.采用主从服务器这种架构,稳定性得以提升.如果主服务器发生故障,我们可以使用从服务器来提供服务. 2.在主从服务器上分开处理用户的请求,可以提升数据处理效率. 3. ...