gpt4 book ai didi

sql - 我如何重写此查询以避免错误 : You can't specify target table for update in FROM clause

转载 作者:行者123 更新时间:2023-11-29 02:36:02 25 4
gpt4 key购买 nike

update websites set master = 2 where url = select url from websites where id = 12;

显然 mysql 不允许您对正在更新的表运行选择查询。

最佳答案

将其放入派生表中。 This gets materialised into a temp table and gets around the restriction .

update websites
set master = 2
where url in (select url
from (select url
from websites
where id = 12) t);

关于sql - 我如何重写此查询以避免错误 : You can't specify target table for update in FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5031041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com