[leetcode] 196. Delete Duplicate Emails
2022. 10. 25. 17:26ㆍSQL
DELETE
1. 기본 구문
DELETE
FROM 테이블명 ;
2. 조건이 있을때
DELETE
FROM 테이블명
WHERE 조건절 ;
리트코드 정답 쿼리
1. 서브쿼리 사용
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 )
2. 셀프 조인 사용
DELETE p1
FROM person AS p1
INNER JOIN person AS p2
ON p1.email = p2.email
WHERE p1.id > p2.id
'SQL' 카테고리의 다른 글
DML (0) | 2022.10.28 |
---|---|
[LeetCode] 627. Swap Salary (0) | 2022.10.25 |
[LeetCode] 1965. Employees With Missing Information (0) | 2022.06.16 |
[LeetCode] 626. Exchange Seats (0) | 2022.06.09 |
[LeetCode] 180. Consecutive Numbers (0) | 2022.06.09 |