我如何重写此查询以避免错误:您不能在FROM子句中指定要更新的目标表 [英] How can I rewrite this query so as to avoid the error: You can't specify target table for update in FROM clause
本文介绍了我如何重写此查询以避免错误:您不能在FROM子句中指定要更新的目标表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
update websites set master = 2 where url = select url from websites where id = 12;
显然,mysql不允许您在要更新的表上运行选择查询.
Apparently mysql won't allow you to run a select query on table you're updating.
推荐答案
将其放入派生表中. 这会得到体现在临时表中并绕过限制.
Put it into a derived table. 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);
这篇关于我如何重写此查询以避免错误:您不能在FROM子句中指定要更新的目标表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文