mysql中 You can’t specify target table for update in FROM clause 解决方案

在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就不会出现上面的错误。

posted @   Sherlock先生  阅读(666)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示