196. Delete Duplicate Emails

Delete duplicate emails, keeping for each email only the row with the smallest id.

DELETE … USING joins the table with itself: a row is deleted when another row has the same email and a smaller id.

Lesson: changing data.

Solutions

DELETE FROM Person p
USING Person q
WHERE p.email = q.email AND p.id > q.id;