在mysql中更新数据,出现 You can't specify target table for update in FROM clause 错误,这句话意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。
update table set del_flag = '2' where id = #{id} OR dept_id IN (SELECT t.id FROM table t WHERE find_in_set(#{id}, ancestors)
解决方案:
再嵌套一层子查询
update table set del_flag = '2' where id = #{id} OR dept_id IN (select tt.id from (SELECT t.id FROM table t WHERE find_in_set(#{id}, ancestors)) tt)
在oracle就不会出现上面的错误。
标签:set,target,clause,update,mysql,table,id From: https://www.cnblogs.com/Baker-Street/p/17614967.html