문제
Write a solution to delete all duplicate emails, keeping only one unique email with the smallest id.
For SQL users, please note that you are supposed to write a DELETE statement and not a SELECT one.
For Pandas users, please note that you are supposed to modify Person in place.
After running your script, the answer shown is the Person table. The driver will first compile and run your piece of code and then show the Person table. The final order of the Person table does not matter.
중복된 이메일이 있으면 id가 작은 이메일만 출력되도록 하면 된다.
쿼리
DELETE FROM person
WHERE id NOT IN (
SELECT minId
FROM (
SELECT MIN(id) AS minId
FROM person
GROUP BY email
) A
);
오류인지 작성하는 모든 select 쿼리가 똑같은 결과가 나와서 당황스러웠다. delete 쿼리로 다 작성해주고 실행시켜야 결과가 제대로 표시되는 듯 하다.
문제 출처
'Study > SQL' 카테고리의 다른 글
| [LeetCode] 570. Managers with at Least 5 Direct Reports (0) | 2026.02.05 |
|---|---|
| [LeetCode] 97. Rising Temperature (0) | 2025.12.02 |
| [LeetCode] 185. Department Top Three Salaries (0) | 2025.11.27 |
| [LeetCode] 184. Department Highest Salary (0) | 2025.11.25 |
| [LeetCode] 183. Customers Who Never Order (0) | 2025.11.25 |