mysql uodate 报错 You can't specify target table '**' for update in FROM clause

Posted 宅小涛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql uodate 报错 You can't specify target table '**' for update in FROM clause相关的知识,希望对你有一定的参考价值。

 You can\'t specify target table \'sc\' for update in FROM clause

背景:把“sc”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩; 

上面的sql是我写的,执行就报这个错,这个原因说的是 不能从自己表里查数据再更新自己

解决方法:嵌套一层中间表

update sc set sc.score = 
(select t1.score from (select avg(sc1.score) score from sc sc1 where sc1.c_id=(select course.c_id from teacher,course where course.t_id=teacher.t_id and tname=\'叶平\')) t1)
where sc.c_id = (select course.c_id from teacher,course where course.t_id=teacher.t_id and tname=\'叶平\');

这种问题仅存在于mysql中,在Oracle中是不存在的,因此在此打个mark 以防下次又忘记了

以上是关于mysql uodate 报错 You can't specify target table '**' for update in FROM clause的主要内容,如果未能解决你的问题,请参考以下文章

mysql - sql报错You can't specify target table 'table_name' for update in FROM clause

mysql中You can't specify target table for update in FROM clause

Mysql更新数据时,报 “You can't specify target table 'message ' 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 for update in FROM clause错误解决方法

Install报错Error: Can‘t find Python executable “python“, you can set the PYTHON env var