1.问题描述
在联合两张表进行更新的时候,出现了以下问题:
You can't specify target table 'XX' for update in FROM clause
大意是: 不能在from子句中指定表“xx”,一般这个XX是需要更新的表名。
2.解决方法
来源stackoverflow的解决方法如下:
update x
set available_material_id = null
where id not in (select id from x where additional_info = 1);
应该如下:
update x
left join x xx on x.id = xx.id and xx.additional_info = 1
set available_material_id = null
where xx.id is null;
https://stackoverflow.com/questions/51087937/on-update-mysql-row-you-cant-specify-target-table-x-for-update-in-from-claus