[코드카타] SQL 60 Delete Duplicate Emails

Data_Student·2024년 12월 9일
0

코드카타

목록 보기
70/82

[코드카타] SQL 60 Delete Duplicate Emails

60. Delete Duplicate Emails
https://leetcode.com/problems/delete-duplicate-emails/description/

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.
Delete p1
From Person p1
join Person P2 on p1.email=p2.email
where p1.id>p2.id
Self Join 을 통해 email이 같은 값을 찾고, 그 중 id 값이 큰 row를 제거
Delete를 처음 사용한 만큼 이 구조에 대해 이해가 필요!

0개의 댓글