Published on

Leetcode - 196. Delete Duplicate Emails

Authors
  • avatar
    Name
    Indo Yoon
    Twitter
Table of Contents

문제

[Loading...

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

LeetCode

](https://leetcode.com/problems/delete-duplicate-emails/)

정답

서브쿼리를 사용하는 방법

DELETE FROM Person
WHERE id NOT IN 
(
    SELECT MIN(id)
    FROM (SELECT * FROM Person) AS temp
    GROUP BY email
);

하나의 테이블을 ALIAS로 두 번 가져오는 방법

DELETE p1 FROM Person p1, Person p2
WHERE
    p1.Email = p2.Email AND p1.Id > p2.Id