# 思路1

使用内联结

```sql
DELETE P1
FROM Person P1 JOIN Person P2
ON
    P1.Email=P2.Email AND
    P1.Id>P2.Id;
```

先用Email内联结

```sql
MariaDB [test]> select * from Person p1 inner join Person p2 on p1.Email=p2.Email;
+----+------------------+----+------------------+
| Id | Email            | Id | Email            |
+----+------------------+----+------------------+
|  1 | john@example.com |  1 | john@example.com |
|  3 | john@example.com |  1 | john@example.com |
|  2 | bob@example.com  |  2 | bob@example.com  |
|  1 | john@example.com |  3 | john@example.com |
|  3 | john@example.com |  3 | john@example.com |
+----+------------------+----+------------------+
```

再加上Id大于的判断

```sql
MariaDB [test]> select * from Person p1 inner join Person p2 on p1.Email=p2.Email AND p1.Id>p2.Id;
+----+------------------+----+------------------+
| Id | Email            | Id | Email            |
+----+------------------+----+------------------+
|  3 | john@example.com |  1 | john@example.com |
+----+------------------+----+------------------+
```

最后把select改成delete就能删除了。注意delet后面跟的是表名。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://851958789.gitbook.io/notes/0196_delete_duplicate_emails/slt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
