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

时间:2021-07-05 08:20:47
DELETE FROM Person WHERE Id NOT IN (
   --mysql不能先select出同一表中的某些值,再update这个表(在同一语句中)
SELECT MIN(p.Id) AS Id FROM Person p GROUP BY p.Email ) ;
DELETE FROM Person WHERE Id NOT IN (
--把临时表再select以下就好了
SELECT Id FROM ( SELECT MIN(p.Id) AS Id FROM Person p GROUP BY p.Email) temp ) ;