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 |
+----+------------------+
 # Write your MySQL query statement below
delete p1
from Person p1,Person p2
where p1.Email=p2.Email
and p1.Id>p2.Id;

[SQL]196. Delete Duplicate Emails的更多相关文章

  1. leetcode【sql】 Delete Duplicate Emails

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

  2. 196. Delete Duplicate Emails

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

  3. 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 ...

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

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

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

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

  6. [LeetCode] 196. Delete Duplicate Emails_Easy tag: SQL

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

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

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

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

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

  9. 【SQL】182. Duplicate Emails

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

随机推荐

  1. mysql的force index

    MSQL中使用order by 有个坑,会默认走order by 后面的索引.而不走where条件里应该走的索引.大家在使用时要绕过此坑. 如下语句因为order by 走了settle_id这个主键 ...

  2. Linux查看日志三种命令

    第一种:查看实时变化的日志(比较吃内存) 最常用的: tail -f filename (默认最后10行,相当于增加参数 -n 10) Ctrl+c 是退出tail命令   其他情况: tail -n ...

  3. [译] 用HTML5捕获音频和视频

    原文地址:http://www.html5rocks.com/en/tutorials/getusermedia/intro/ 概述 有了HTML5,我们就可以在不借助Flash或者Silverlig ...

  4. Hibernate5笔记5--关联关系映射

    关联关系映射: 关联关系,是使用最多的一种关系,非常重要.在内存中反映为实体关系,映射到DB中为主外键关系.实体间的关联,即对外键的维护.关联关系的发生,即对外键数据的改变. 外键:外面的主键,即,使 ...

  5. linux下pip安装无法连接官网

    为了安装pwntools等工具,要先安装pip,系统安装好了,却遇到了无法连接到pip官网的报错,找了半天方法最终解决 wget https://bootstrap.pypa.io/get-pip.p ...

  6. ksh函数

    在不同的shell环境里,shell脚本的写法是不同的 此链接为ksh环境的函数写法: https://blog.csdn.net/shangboerds/article/details/487115 ...

  7. ubuntu下将程序挂后台命令

    ubuntu下将程序挂后台命令 nohup python -u main.py > test.out 2>&1 & ubunut下查看后台进程 jobs -l

  8. SQL Case when 的使用方法 (转)

    Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END ...

  9. Linux学习笔记:644、755、777权限详解

    一.问题 1.在Linux或者Android系统下用命令ll或者ls -la的时候会看到前面-rw-rw-r--一串字符,不知道代表什么? 2.新建vi一个文件之后,经常需要chmod 755 fil ...

  10. 20165203 2017-2018-2 《Java程序设计》课程总结

    20165203 2017-2018-2 <Java程序设计>课程总结 一.每周作业及实验报告链接汇总 我期望的师生关系(预备作业一):浅谈一下对师生关系的看法和对自己未来学习和生活的期望 ...