以上错误在mysql官方是这样说明的:
You can use a subquery for assignment within an UPDATE statement because subqueries are legal in UPDATE and DELETE statements as well as in SELECT statements. However, you cannot use the same table (in this case, table t1) for both the subquery FROM clause and the update target.
大意为:在更新或删除目标表中数据的时候如果使用子查询,目标表不能在子查询的FROM语句中出现,比如下面的语句是错误的:
1 | UPDATE t1 SET column2 = (SELECT MAX(column1) FROM t1); |
可以这样修改:
1 | UPDATE t1 SET column2 = (SELECT * from (SELECT MAX(column1) FROM t1) t); |
用别名”t”代替了子查询中的目标表”t1”。