0

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.

Query:

DELETE FROM person WHERE `Id` not in (SELECT MIN(`Id`)
                                    FROM person
                                    GROUP BY `Email`)

Error ->

You can't specify target table 'person' for update in FROM clause

Why Am I getting this error? It should delete each rows that have ids greater than min.

Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0