링크
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.
정답
with soso as
(
select min(id) as min_id
from person
group by email
)
delete
from person
where id not in (select min_id from soso)
해설
- delete 문법
delete
from table_name
where column = value
DELETE 문은 해당 테이블에서 WHERE 절의 조건을 만족하는 레코드만을 삭제
즉, 테이블에서 명시된 필드와, 그 값이 일치하는 레코드만을 삭제
만약 WHERE 절을 생략하면, 해당 테이블에 저장된 모든 데이터가 삭제
'[업무 지식] > MySQL' 카테고리의 다른 글
[GROUP_CONCAT] Group Sold Products By The Date (0) | 2024.11.18 |
---|---|
[Limit/Offset] Second Highest Salary (0) | 2024.11.18 |
[LIKE] Patients With a Condition (0) | 2024.11.14 |
[upper, lower] Fix Names in a Table (0) | 2024.11.14 |
[row/between] 프레임 정의 (0) | 2024.11.12 |