开发者

How can I rewrite this query so as to avoid the error: You can't specify target table for update in FROM clause

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

Apparently mysql won't allow you t开发者_运维技巧o 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);  


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜