Write an SQL query to delete all the duplicate emails, keeping only one unique email with the smallest id. Note that you are supposed to write a DELETE statement and not a SELECT one.
풀이
제출한 오답
delete from Person
where (email, id) not in (
select email, min(id) as min_id
from Person
group by email)
-> 서브쿼리를 한 번만 사용할 수는 없을까 해서 where 절에 다중컬럼 서브쿼리를 사용했지만 에러가 났다.
다시 제출한 답
delete from Person
where id not in
(select sub.min_id
from(
select email, min(id) as min_id
from Person
group by email) sub)
'데이터 분석 > SQL 연습문제' 카테고리의 다른 글
184. Department Highest Salary (LeetCode) (0) | 2022.09.18 |
---|---|
Top Earners (HackerRank) (0) | 2022.09.17 |
627. Swap Salary (LeetCode) (0) | 2022.09.15 |
코테 연습 26일차 (프로그래머스 SQL 고득점 Kit) (0) | 2022.03.09 |
코테 연습 25일차 (프로그래머스 SQL 고득점 Kit) (0) | 2022.03.08 |
댓글