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出同一表中的某些值,再update这个表(在同一语句中),这个问题只出现于mysql,sqlserver和oracle不会出现此问题

解决办法:将select出的结果再通过中间表select一遍

delete from user where username in (select a.username from(select username from user group by username having count(username)>1)a);

这样delete和select的就不是同一个表了

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

时间: 2024-11-09 00:49:37

mysql中You can't specify target table for update in FROM clause的相关文章

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 &#39;表名&#39; for update in FROM clause错误解决办法

背景 在MySQL中,写SQL语句的时候 ,可能会遇到 You can't specify target table '表名' for update in FROM clause 这样的错误 错误含义 它的意思是说,不能先 select 出同一表中的某些值,再 update 这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值. 解决问题 将select出的结果再通过中间表select一遍,这样就可以解决错误了 MySQL 中 You can't specify target ta

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 uodate 报错 You can&#39;t specify target table &#39;**&#39; 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 sc

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

update mysql row (You can&#39;t specify target table &#39;x&#39; for update in FROM clause)

sql语句(update/delete都会出现此问题) update x set available_material_id = null where id not in (select id from x where additional_info = 1); mistake 大致意思是,在同一语句中,不能先select出同一表中的某些值,再update这个表. You can't specify target table 'x' for update in FROM clause mysql