sql mysql错误您无法在FROM子句中指定要更新的目标表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql mysql错误您无法在FROM子句中指定要更新的目标表相关的知识,希望对你有一定的参考价值。


accepted
Update: This answer covers the general error classification. For a more specific answer about how to best handle the OP's exact query, please see DanDarc's answer

In MySQL, you can't modify the same table which you use in the SELECT part.
This behaviour is documented at: http://dev.mysql.com/doc/refman/5.6/en/update.html

You will need to stop using the nested subquery and execute the operation in two parts, or alternatively use a simple where clause.

Below is from Baron Schwartz, published at Nabble:

However, you can do multi-table updates like this:

UPDATE tbl AS a
  INNER JOIN tbl AS b ON ....
  SET a.col = b.col
If you absolutely need the subquery, there's a workaround, but it's ugly for several reasons, including performance:

UPDATE tbl SET col = (
  SELECT ... FROM (SELECT.... FROM) AS x);
The nested subquery in the FROM clause creates an implicit temporary table, so it doesn't count as the same table you're updating.

以上是关于sql mysql错误您无法在FROM子句中指定要更新的目标表的主要内容,如果未能解决你的问题,请参考以下文章

Mysql 错误:1093 - 无法在 FROM 子句中指定要更新的目标表

MySQL 错误 1093 - 无法在 FROM 子句中指定要更新的目标表(两个连接)

mysql - 您不能在 FROM 子句中指定要更新的目标表(我的查询有效,但不是等效更新)

您不能在 FROM 子句中指定要更新的目标表

#1093 - 您不能在 FROM 子句中指定要更新的目标表 [重复]

ERROR 1093 (HY000): 您不能在 FROM 子句中指定要更新的目标表