Mysql中You can’t specify target table for update in FROM clause错误解决方法
Posted dingwen_blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql中You can’t specify target table for update in FROM clause错误解决方法相关的知识,希望对你有一定的参考价值。
问题描述:
mysql删选出同一张表的主键集合再使用该表的主键
in
进行删除报错。注意,这个问题只出现于mysql,mssql和oracle不会出现此问题。
原因分析:
Mysql不能先select出同一表中的某些值,再update这个表(在同一语句中)。
解决方案:
将select出的结果再通过中间表select一遍
delete from `user` u1 where u1.id in(
select u3.id from (
select u2.id from `user` u2
) u3
)
以上是关于Mysql中You can’t specify target table for update in FROM clause错误解决方法的主要内容,如果未能解决你的问题,请参考以下文章