You can't specify target table 'test' for update in FROM clause.mysql
MySQL中You can't specify target table <test> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。 例以下面这个sql:sql
update test set `status`=3 where id in(select * from test where status=-50);oracle
改写成下面就好了:.net
update test set `status`=3 where id in(select a.id from (select * from test where status=-50) a);ci
也就是说将select出的结果再经过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,mssql和Oracle不会出现此问题。get