首页 > 数据库 >mysql中 You can’t specify target table for update in FROM clause 解决方案

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

时间:2023-08-08 17:34:59浏览次数:40  
标签:set target clause update mysql table id

在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

相关文章

  • How to update to the latest Python version On Linux All In One
    HowtoupdatetothelatestPythonversionOnLinuxAllInOneupdatetothelatestPythonversiononRaspberryPierrorsold$python--versionPython3.9.2new$sudoaptupdate$aptlist|greppython3.10WARNING:aptdoesnothaveastableCL......
  • [Javascript] event target and currentTarget
    <Parent><child><button/></child></Parent>functiononClick(event){console.log('target:',event.target)//buttonconsole.log('currentTarget',event.currentTarget)//parent}pa......
  • iptables: No chain/target/match by that name
    部署完docker后执行脚本报错在启动run.sh脚本后出现iptables:Nochain/target/matchbythatname.报错解决办法:重启dockerPS:重启docker后,通过以下命令可以查看最新防火墙配置:iptables-L应该看到iptables配置中ChainDocker设置已更新(与1中历史结果进行对比)原因解释重新......
  • update-alternatives 使用详解
    alternatives管理方式$ls-l/usr/bin/pythonlrwxrwxrwx1rootroot2411202017/usr/bin/python->/etc/alternatives/python$ls-l/etc/alternatives/pythonlrwxrwxrwx1rootroot1811212017/etc/alternatives/python->/usr/bin/python2.7python这个可执行命......
  • 红帽SELinux资料-翻译---第三章-Targeted策略
        红帽企业Linux7SELinux用户和管理员指南  翻译者:李天聪        第三章    Targeted策略Targeted策略是红帽企业Linux的默认SELinux策略。当使用targeted策略时,目标进程运行在受限的域中,非目标进程运行在不受限的域中。例如,默认情况下,登......
  • java报错:unable to find valid certification path to requested target
    问题发现unabletofindvalidcertificationpathtorequestedtarget当我使用java代码访问某个URL的时候,报了这个错误,经过查询发现需要安装证书到java环境,所以记录一下。下载证书我使用的是chrome浏览器,点击地址栏左边小锁,选择第一个选项。然后选择证书有效。在弹出的......
  • 报错:This generated password is for development use only. Your security configura
    项目报错:Thisgeneratedpasswordisfordevelopmentuseonly.Yoursecurityconfigurationmustbeupdatedbeforerunningyourapplicationinproduction.导致postman测试接口时报错:401UnauthorizedSimilarto403Forbidden,butspecificallyforusewhenauthenticat......
  • 浅谈-BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(Object targe
    BeanWrapper是SpringFramework中的一个接口,它提供了一种方便的方式来访问Java对象的属性,并允许对属性进行读取和设置操作。PropertyAccessorFactory.forBeanPropertyAccess(this)是一个工厂方法,用于创建一个BeanWrapper对象,以便访问指定的Java对象的属性。举个例子来......
  • 统信UOS专业版 apt update失败问题解决方法
    UOSaptupdate时提示‘仓库“https://pro-store-packages.uniontech.com/appstoreeagle-proInRelease”的签名不再生效’只需要更改/etc/apt/sources.list.d/appstore.list文件内容,改为debhttps://com-store-packages.uniontech.com/appstoredeepinappstore同时,建......
  • vue3之父组件中封了子组件的抽屉(弹框类),通过update:modelValue来进行父子组件的v-mod
    eg:父组件a.vue<AddAiDrawer:projectId="route.query.id"v-model="addAiShow"title="新增"type="spaceAi"@call-back-table="refreshTa......