SQL
leetcode > 196. Delete Duplicate Emails
jhj.sharon
2023. 2. 6. 16:41
반응형
✨ 문제
196. Delete Duplicate Emails
https://leetcode.com/problems/delete-duplicate-emails/description/?envType=study-plan&id=sql-i
Delete Duplicate Emails - LeetCode
Delete Duplicate Emails - Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id is the primary key column for this table. Each row of this table contains an em
leetcode.com
💻코드
👩💻 풀이 방법
- 중복된 이메일 주소를 지우는 문제이다. 만약 중복된 이메일 주소가 있다면 ID가 큰 것을 지우는 조건이다.
- WHERE절에서 비교를 위해 삭제하지 않고 남긴 ID를 뽑아주는 서브쿼리를 먼저 작성했다.
- 셀프 조인, 즉 같은 테이블을 비교하는 경우에 하나의 테이블만 별칭을 정해주어도 된다.
🔔 느낀점
- 가끔 LEETCODE에서 비교연산자 <>를 잘 인식하지 못하는 것 같다.
반응형