---
# System prepended metadata

title: \#196 Delete Duplicate Emails
tags: [leetcode, leetcode-easy, sql]

---

# \#196 Delete Duplicate Emails
## *刪除tabl中重複的email(保留id最小者)*
## Log
 - build 20210422 by syhuang

## xxx
 - xxx
```javascript=
```
## 較易理解的解法
 - group搭配min, 用not in排除刪除範圍外, 注意因為要異動同個table, 因此用這個方法要"鏡像"(t)
```sql=
delete from Person where id not in(
select t.id from(
    select min(p.id) id from Person p group by p.email
)t)
```
## 備註
## 參考
 - https://leetcode.com/problems/delete-duplicate-emails/discuss/55614/A-skillful-mysql-solution-avoid-%22-select-and-update-conflict%22
###### tags: `leetcode`, `leetcode-easy`, `sql`