From e231d028f571ff1f3ab13bb4a8d8e286f606a0f8 Mon Sep 17 00:00:00 2001 From: Antim Pal <134076504+iamAntimPal@users.noreply.github.com> Date: Sun, 23 Mar 2025 22:53:19 +0530 Subject: [PATCH 1/2] Create 196. Delete Duplicate Emails.sql --- .../196. Delete Duplicate Emails.sql | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql diff --git a/LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql b/LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql new file mode 100644 index 0000000..a81f41a --- /dev/null +++ b/LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql @@ -0,0 +1,53 @@ +196. Delete Duplicate Emails +Solved +Easy +Topics +Companies +SQL Schema +Pandas Schema +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. + + + From ead49ee35b22341ca7771ab30e917fbb331645b9 Mon Sep 17 00:00:00 2001 From: Antim Pal <134076504+iamAntimPal@users.noreply.github.com> Date: Sun, 23 Mar 2025 22:53:27 +0530 Subject: [PATCH 2/2] Update 196. Delete Duplicate Emails.sql --- LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql b/LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql index a81f41a..214afb4 100644 --- a/LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql +++ b/LeetCode SQL 50 Solution/196. Delete Duplicate Emails.sql @@ -51,3 +51,8 @@ Explanation: john@example.com is repeated two times. We keep the row with the sm +# Write your MySQL query statement below +# Write your MySQL query statement below +DELETE p2 FROM Person p1 +JOIN Person p2 +ON p1.email = p2.email AND p1.id < p2.id; \ No newline at end of file