您好,欢迎访问一九零五行业门户网

You can't specify target table for update in FR

今天执行一个mysql语句的时候,出现错误提示:you can't specify target table for update in from clause
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)
其它类似信息

推荐信息