MySQL : You can't specify target table 'Person' for update in FROM clause
Posted 木析
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL : You can't specify target table 'Person' for update in FROM clause相关的知识,希望对你有一定的参考价值。
原因:mysql不能在同一语句中先select出同一表中的某些值,再对这个表做修改
解决方法:添加临时表
参考:https://blog.csdn.net/baidu456356/article/details/101603359
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
) ;
以上是关于MySQL : You can't specify target table 'Person' for update in FROM clause的主要内容,如果未能解决你的问题,请参考以下文章
MySQL : You can't specify target table 'Person' for update in FROM clause
mysql中You can't specify target table for update in FROM clause
Mysql -- You can't specify target table 'address' for update in FROM clause
mysql:You can't specify target table 'bpm_tksign_data' for update in FROM clause
mysql uodate 报错 You can't specify target table '**' for update in FROM clause
mySQL: delete 语句报错 You can't specify target table 'student' for update in FROM clause(示例