参考: https://www.jb51.net/article/60926.htm
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。
例如:将id=2且name不等于null的数据的name设置为'abc',
首先要查出该数据再更新,如下:会报You can't specify target table for update in FROM clause错误!!!
UPDATE a SET name = 'abc' WHERE id = (select id from a where id = 2 and name is null);
改为:
update a set name = 'abc' where id = (select id from (select * from a where id = 2 and name is null) as b)