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. vuex - 辅助函数学习

    官网文档: https://vuex.vuejs.org/zh-cn/api.html  最底部 mapState 此函数返回一个对象,生成计算属性 - 当一个组件需要获取多个状态时候,将这些状态都声 ...

  2. JS笔记 - JQ事件委托( 适用于给动态生成的脚本元素添加事件)

    最近一段时间打了一个大仗,现在总算消停点,才有时间来做个总结吧算是: 移动端遇到一个项目,是一个列表的侧滑栏,在我这里用jq写的交互事件.自测各方面都挺好的,美滋滋的给了研发.研发也美滋滋的开始开发. ...

  3. wex5 onactive不执行的解决办法

    由index.w点击某个图片,转到adetail,希望每次adetail加载时,取到参数id index.w <tbody class="x-list-template" x ...

  4. ftp主动与被动模式区别

    FTP是仅基于TCP的服务,不支持UDP.与众不同的是FTP使用2个端口,一个数据端口和一个命令端口(也可叫做控制端口).通常来说这两个端口是21(命令端口)和20(数据端口).但FTP工作方式的不同 ...

  5. import 与 from…import 的区别

    首先你要了解 import 与 from…import 的区别. import 模块:导入一个模块:注:相当于导入的是一个文件夹,是个相对路径. from…import:导入了一个模块中的一个函数:注 ...

  6. 【BZOJ5133】[CodePlus2017年12月]白金元首与独舞 矩阵树定理

    [BZOJ5133][CodePlus2017年12月]白金元首与独舞 题面:www.lydsy.com/JudgeOnline/upload/201712/div1.pdf 题解:由于k很小,考虑用 ...

  7. Weibull分布(韦伯分布、威布尔分布)

    log函数 从概率论和统计学角度看,Weibull Distribution是连续性的概率分布,其概率密度为: 其中,x是随机变量,λ>0是比例参数(scale parameter),k> ...

  8. Spark2 Dataset行列操作和执行计划

    Dataset是一个强类型的特定领域的对象,这种对象可以函数式或者关系操作并行地转换.每个Dataset也有一个被称为一个DataFrame的类型化视图,这种DataFrame是Row类型的Datas ...

  9. R序列seq

    > seq(from=10,to=20,by=3) [1] 10 13 16 19 > seq(from=10,to=20,length=5) [1] 10.0 12.5 15.0 17. ...

  10. C#控制台窗口居中显示(转)

    private struct RECT { public int left, top, right, bottom; } [DllImport("kernel32.dll", Se ...