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

原文地址:https://www.cnblogs.com/zhaiyt/p/10475173.html

时间: 2024-08-07 02:16:50

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

今天写了个更新数据库表的语句,本意是根据某个条件,筛选出该表某些数据之后,对这些数据进行删除操作,如下 delete from t_person where id in (select id from t_person where name = "hello"); 然而却报错: You can't specify target table 't_person' for update in FROM clause 以下这篇博客( https://blog.csdn.net/qq_2967

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

使用mysql在删除表中重复记录 delete from user where username in (select user name form(select username from user group by username having count(username)>1)); 遇到mysql报错You can't specify target table for update in FROM clause 上网百度了下原来是mysql中不允许先select出同一表中的某些值,再u

mysql中You can’t specify target table for update in FROM clause错误解决方法

mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中). 例如下面这个sql: 1 delete from tbl where id in 2 ( 3 select max(id) from tbl a where EXISTS 4 ( 5 select 1 from tbl b where a.tac=b.tac group by ta

MySQL中You can't specify target table for update in FROM clause一场

mysql中You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中). 如下l: 需要将select出的结果再通过中间表select一遍,就可以规避了错误. 如下: PS:这个问题只出现于mysql,sql service 和 oracle 不会出现此问题. MySQL中You can't specify target table for

mysql中You can&#39;t specify target table for update in FROM clause错误

MySQL中You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中). 例如下面这个sql: delete from tbl where id in ( select max(id) from tbl a where EXISTS ( select 1 from tbl b where a.tac=b.tac group by tac H

mysql error:You can&#39;t specify target table for update in FROM clause

mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中). 例如下面这个sql: 代码如下: delete from tbl where id in ( select max(id) from tbl a where EXISTS ( select 1 from tbl b where a.tac=b.tac group by tac HA

mysql修改删除You can&#39;t specify target table for update in FROM clause的问题

表中出现重复数据,需要删除重复数据,只保留一条 DELETE FROM crm_participant WHERE id IN ( SELECT c.id cid FROM crm_participant c WHERE c.parentPhone IN ( SELECT a.parentPhone FROM crm_participant a GROUP BY a.parentPhone HAVING count( a.parentPhone ) > 1 ) AND c.id NOT IN (

MySQL can’t specify target table for update in FROM clause

翻译:MySQL不能指定更新的目标表在FROM子句 源SQL语句: [sql] view plain copy print? delete from t_official_sys_user where USER_NAME IN(SELECT USER_NAME FROM t_official_sys_user b group by b.`USER_NAME` having  count(1) > 1) 执行报以下错误: [sql] view plain copy print? [SQL] del

mysql编译报错

1.make报错现象 Warning: Bison executable not found in PATH 解决办法 yum -y install bison 2.make报错现象 ake Error at /usr/share/cmake-2.8/Modules/CMakeCXXInformation.cmake:17 (get_filename_component):get_filename_component called with incorrect number of argumen