You can't specify target table for update in FR
程序员文章站
2022-05-29 11:29:36
...
今天执行一个mysql语句的时候,出现错误提示:You can't specify target table for update in FROM clause
mysql 语句如下;
mysql 语句如下;
UPDATE school_more_info SET comments = replace( comments, '�', "'" ) WHERE school_id IN (SELECT school_id FROM school_more_info WHERE comments LIKE '%�%')
这个sql的意思是将comments字段中的�替换更新成‘, 更新的条件是只有含有�的行才更新,没有�的行则不更新。咋一看,应该没有错啊,我们经常这么写。最后查资料,mysql中不能这么用,那串英文错误提示就是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。
改写后的sql,这样是可以正确执行的。如下:
UPDATE school_more_info SET comments = replace( comments, '�', "'" ) WHERE school_id IN (SELECT school_id FROM (SELECT *FROM school_more_info WHERE comments LIKE '%�%') AS a)
上一篇: mysql两表数据全表复制方法
推荐阅读
-
mysql 批量删除/更新数据报错 you can‘t specify target / every derrived table must / you are using safe update
-
mysql update语句问题:You can't specify target table 'user_MySQL
-
mysql update语句问题:You can't specify target table 'user_MySQL
-
mysql 一个较特殊的问题:You can't specify target table 'wm_MySQL
-
You can't specify target table for update in FR
-
You can't specify target table for update in FR
-
mysql 批量删除/更新数据报错 you can‘t specify target / every derrived table must / you are using safe update
-
解决:[Err] 1093 - You can't specify target table 'air_ticket' for update in FROM clause
-
mysql中You can’t specify target table for update in FROM clau_MySQL
-
mysql 一个较特殊的问题:You can''t specify target table '