更新数据库的时候,提示: You can't specify target table 'channels' for update in FROM clause
出错的SQL是什么呢?
出错的是SQL是:
update channels set parentid = 0 where parentid in (select b.id from channels b where b.parentid = 0) ;
从理论上来看好象没什么错,但就是出现上面的错误(You can't specify target table 'channels' for update in FROM clause),说是不能在原表操作。于是改正它。。
改成:
update channels set parentid = 0 where parentid IN ( select id from (SELECT id from channels where parentid = 0) as tmp )
看上去是不是很恶心?但确实是通过临时表来解决了这个问题。。。
好吧,我又恶心了