I have a table named P, which has two columns: id and email. All the id are different and in ascending order, but some id have the same email. I need to delete all the duplicated emails and keep only unique emails with its smallest id. The correct query is:
DELETE FROM P
WHERE id NOT IN
(
SELECT minId FROM
(
SELECT MIN(id) AS minId, email
FROM P
GROUP BY email
) AS Q
)
However, it I use the following query, which returns "SyntaxError: near 'AS Q'". Could anybody tell me why. Thanks.
DELETE FROM P
WHERE id NOT IN
(SELECT MIN(id)
FROM P
GROUP BY email
) AS Q