강의

멘토링

로드맵

Inflearn Community Q&A

hyeyun1330116's profile image
hyeyun1330116

asked

[A hundred words are not as good as seeing once] Advanced SQL for data analysis

DELETE LeetCode Problem Solving + Section 3 Subquery Preview

Leetcode 196. Delete Duplicate Emails 서브쿼리 관련

Written on

·

447

0

안녕하세요! Leetcode 196. Delete Duplicate Emails 문제 관련해서 질문 드립니다.

강의에서는 서브쿼리를 두 번 사용했는데 아래와 같이 where 절에 다중컬럼 서브쿼리를 사용해서 서브쿼리를 한 번만 사용할 수는 없는 걸까요? "You can't specify target table 'Person' for update in FROM clause" 같은 에러가 납니다.

delete from Person 
where (email, id) not in (
select email, min(id) as min_id 
from Person 
group by email)
sql

Answer 1

1

jaemin님의 프로필 이미지
jaemin
Instructor

네, 바로 그 에러 때문에 서브쿼리를 두 번 사용해야 합니다.

에러의 내용은 DELETE 명령이 일어나는 테이블 Person을 WHERE 절에서 직접 참조(SELECT)하는 것이 불가능하다는 의미입니다.

hyeyun1330116's profile image
hyeyun1330116

asked

Ask a question