mysql中【update/Delete】update中无法用基于被更新表的子查询,You can't specify target table 'test1' for update in FROM clause.

关键词:mysql update,mysql delete

update中无法用基于被更新表的子查询,You can't specify target table 'test1' for update in FROM clause.

情况如下:

(1)第1行更新语句中,update表与子查询中表一样,所以报错

(2)第2行更新语句中,update表与子查询中表不一样,所以可以执行。

如何解决?

把子查询换成join即可。

例如:

总结:

  (1)在update与delete中,都不能再以子查询的方式调用其表本身(因为一致性的关系),否则会报错。

  (2)但可以以派生表的方式 join 使用

原文地址:https://www.cnblogs.com/gered/p/10870680.html