196. Delete Duplicate Emails

Description

Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.

Note:

Your output is the whole Person table after executing your sql. Use delete statement.

Constraints

Approach

  • GeeksforGeeks

  • ProgramCreek

  • YouTube

Examples

Input:

Id is the primary key column for this table.

Output:

Solutions

# MySQL query statement

DELETE p1 
FROM Person p1, Person p2
WHERE p1.Email = P2.Email AND p1.Id > p2.Id

Follow up

Last updated

Was this helpful?