inblog logo
|
silver
    SQL문제풀기

    [SQL문제풀기] Delete Duplicate Emails

    silver's avatar
    silver
    Nov 25, 2025
    [SQL문제풀기] Delete Duplicate Emails
    Contents
    문제MySQL

    문제

    Delete Duplicate Emails - LeetCode
    Can you solve this real interview question? Delete Duplicate Emails - Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id is the primary key (column with unique values) for this table. Each row of this table contains an email. The emails will not contain uppercase letters.   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. For Pandas users, please note that you are supposed to modify Person in place. After running your script, the answer shown is the Person table. The driver will first compile and run your piece of code and then show the Person table. The final order of the Person table does not matter. The result format is in the following example.   Example 1: Input: Person table: +----+------------------+ | id | email | +----+------------------+ | 1 | john@example.com | | 2 | bob@example.com | | 3 | john@example.com | +----+------------------+ Output: +----+------------------+ | id | email | +----+------------------+ | 1 | john@example.com | | 2 | bob@example.com | +----+------------------+ Explanation: john@example.com is repeated two times. We keep the row with the smallest Id = 1.
    Delete Duplicate Emails - LeetCode
    https://leetcode.com/problems/delete-duplicate-emails/description/?envType=study-plan-v2&envId=top-sql-50
    Delete Duplicate Emails - LeetCode

    MySQL

    내가 시도한 쿼리

    : output에 id만 출력되게 해도 결과값이 똑같이 나온다. 페이지 오류인 것 같다.  Discussion을 보니 다른 사람들도 겪고 있는 문제인 것 같았다.
    select min(id) id, email from Person group by email;
    notion image
    notion image
     
    Share article

    silver

    RSS·Powered by Inblog