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. Collection子接口(List/Set/Queue/SortedSet)

    Collection基本的子接口: List:能够存放反复内容 Set:不能存放反复内容,全部反复的内容靠hashCode()和equals()两个方法区分 Queue:队列接口 SortedSet: ...

  2. Windows7 64位系统搭建Cocos2d-x 2.2.1最新版以及Android交叉编译环境(具体教程)

    原文地址:http://blog.csdn.net/sttyytw/article/details/17005263 声明:本教程在參考了下面博文,并经过自己的摸索后实际操作得出,本教程系本人原创,因 ...

  3. RESTful Web Services: A Tutorial--reference

    As REST has become the default for most Web and mobile apps, it's imperative to have the basics at y ...

  4. Android 快速开发系列 打造万能的ListView GridView 适配器

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38902805 ,本文出自[张鸿洋的博客] 1.概述 相信做Android开发的写 ...

  5. 在winform程序中实现按照不同的角色或用户展现不同的页面

    SqlConnection cn = new SqlConnection();             cn.ConnectionString = "Data Source=192.168. ...

  6. 安装ORACLE 11g 64位 pl/sql无法进入的问题。

    转载自网上的内容: 1)安装Oracle 11g 64位 2)安装32位的Oracle客户端( instantclient-basic-win32-11.2.0.1.0)下载地址:http://www ...

  7. 解析xml的几种方式

    http://blog.csdn.net/smcwwh/article/details/7183869

  8. JAVA-5-关于for循环的几个例子

    打印一个*组成的矩形 public static void main(String[] args) { // TODO 自动生成的方法存根 for (int i = 0; i < 5; i++) ...

  9. [置顶] 让你的Android应用与外部元素互动起来

    传送门 ☞ 轮子的专栏 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 一个Android应用程序通常有几个activities.每个act显示一个用户接口允 ...

  10. CentOS 7 之Shell学习笔记

    脚本是个永恒的话题,以前Dos下面也有Shell编程这一说的,比如说BAT文件有人写的好的话,也是瞬间速度变高大上.Linux下面这个应该更占比重了.我看到园子里有位园友做了一个Linux Shell ...