# 一条SQL删除数据表中的重复数据

**URL:** <https://www.shiqidu.com/t/topic/533>\
**Category:** 开发调优\
**Tags:** MySQL\
**Created:** [2018 年12 月 17 日 11:02 UTC](https://www.shiqidu.com/t/topic/533 "2018-12-17T11:02:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2018 年12 月 17 日 11:02 UTC](https://www.shiqidu.com/t/topic/533/1 "2018-12-17T11:02:04Z")

</div>

表中数据如下

![alt text](https://discourse.shiqidu.com/upload/discussion/20181217/cc856a3a0f35371781d1c6c2f598181e_origin.png)

要求删除后出现的重复的数据，即删掉ID为3的数据。

方式一

```sql
delete p1 from duplicate_email as p1,duplicate_email as p2 where p1.email = p2.email and p1.id > p2.id;

```

方式二

```sql
delete p1 from duplicate_email as p1 left join duplicate_email as p2 on p1.email = p2.email where p1.id > p2.id;

```
