我正在尝试更新MySQL行。

我的查询是

update x set available_material_id = null where id not in (select id from x where additional_info = 1);


并且我收到此错误消息:您无法在FROM子句中指定目标表“ x”进行更新

有人可以帮我解决这个问题吗?

我正在使用MySQL版本5.6.38。

我看到了这个You can't specify target table for update in FROM clause答案,但我无法弄清楚。

最佳答案

使用left join

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;

关于mysql - 在更新mysql行时(您不能在FROM子句中指定目标表“x”进行更新),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51087937/

10-15 08:11
查看更多