0
DELETE
FROM Person
WHERE Id IN (
 SELECT Id
 FROM Person
 GROUP BY Email
 HAVING COUNT(*) > 1 AND Id <> MIN(Id)
)

The above query produces the error:

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

Why?

I am just trying to solve this problem to improve my SQL skills.

I checked the above SQL query here and it seems my syntax is fine.

2
  • Specify definite DBMS. MySQL, error 1093? – Akina Mar 28 at 18:27
  • @Akina, yes. You are right. – some1 here Mar 28 at 18:30
1

Use multiple-table DELETE syntax:

DELETE t1.*
FROM Person t1
JOIN Person t2 USING (Email)
WHERE t1.id > t2.id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.