update websites set master = 2 where url = select url from websites where id = 12;
显然mysql不会允许你在你正在更新的表上运行select查询。我该如何重写这个查询,以避免错误:你不能在FROM子句中指定更新的目标表
update websites set master = 2 where url = select url from websites where id = 12;
显然mysql不会允许你在你正在更新的表上运行select查询。我该如何重写这个查询,以避免错误:你不能在FROM子句中指定更新的目标表
把它放到派生表中。 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);
update websites set master = 2 where url in (select w2.url from websites w2 where w2.id = 12);
不,这并不欺骗它。 – HyderA
k, 更新网站w,网站w2设置w2.master = 2其中w.url = w2.url和w2.id = 12); –
为什么+2这不起作用? –
蠢人!谢谢! – HyderA
+1提供解决方案*和*文档! –