{ "data": { "question": { "questionId": "196", "questionFrontendId": "196", "categoryTitle": "Database", "boundTopicId": 1235, "title": "Delete Duplicate Emails", "titleSlug": "delete-duplicate-emails", "content": "

Table: Person

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| email       | varchar |\n+-------------+---------+\nid is the primary key column for this table.\nEach row of this table contains an email. The emails will not contain uppercase letters.\n
\n\n

 

\n\n

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.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nPerson table:\n+----+------------------+\n| id | email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n| 3  | john@example.com |\n+----+------------------+\nOutput: \n+----+------------------+\n| id | email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n+----+------------------+\nExplanation: john@example.com is repeated two times. We keep the row with the smallest Id = 1.\n
\n", "translatedTitle": "删除重复的电子邮箱", "translatedContent": "

表: Person

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| email       | varchar |\n+-------------+---------+\nid是该表的主键列。\n该表的每一行包含一封电子邮件。电子邮件将不包含大写字母。\n
\n\n

 

\n\n

编写一个SQL查询来 删除 所有重复的电子邮件,只保留一个id最小的唯一电子邮件。

\n\n

任意顺序 返回结果表。

\n\n

查询结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入: \nPerson 表:\n+----+------------------+\n| id | email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n| 3  | john@example.com |\n+----+------------------+\n输出: \n+----+------------------+\n| id | email            |\n+----+------------------+\n| 1  | john@example.com |\n| 2  | bob@example.com  |\n+----+------------------+\n解释: john@example.com重复两次。我们保留最小的Id = 1。
\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 464, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Please write a DELETE statement and DO NOT write a SELECT statement.\n# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* \n Please write a DELETE statement and DO NOT write a SELECT statement.\n Write your T-SQL query statement below\n */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/*\n Please write a DELETE statement and DO NOT write a SELECT statement.\n Write your PL/SQL query statement below\n */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"121.1K\", \"totalSubmission\": \"182.5K\", \"totalAcceptedRaw\": 121088, \"totalSubmissionRaw\": 182462, \"acRate\": \"66.4%\"}", "hints": [], "solution": { "id": "98", "canSeeDetail": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "{\"headers\": {\"Person\": [\"id\", \"email\"]}, \"rows\": {\"Person\": [[1, \"john@example.com\"], [2, \"bob@example.com\"], [3, \"john@example.com\"]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Person (Id int, Email varchar(255))\"\n ],\n \"mssql\": [\n \"Create table Person (Id int, Email varchar(255))\"\n ],\n \"oraclesql\": [\n \"Create table Person (Id int, Email varchar(255))\"\n ],\n \"database\": true,\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Person (Id int, Email varchar(255))", "Truncate table Person", "insert into Person (id, email) values ('1', 'john@example.com')", "insert into Person (id, email) values ('2', 'bob@example.com')", "insert into Person (id, email) values ('3', 'john@example.com')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "{\"headers\": {\"Person\": [\"id\", \"email\"]}, \"rows\": {\"Person\": [[1, \"john@example.com\"], [2, \"bob@example.com\"], [3, \"john@example.com\"]]}}", "__typename": "QuestionNode" } } }