iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >You can‘t specify target table ‘表名‘ for update in FROM clause错误
  • 619
分享到

You can‘t specify target table ‘表名‘ for update in FROM clause错误

mysql数据库 2023-09-10 15:09:55 619人浏览 八月长安
摘要

修改 Mysql 一些数据的时候,update 同表子查询筛选的数据,出现了如下错误: #1093 - You can't specify target table 'd_no' for update in FROM clau

修改 Mysql 一些数据的时候,update 同表子查询筛选的数据,出现了如下错误:

#1093 - You can't specify target table 'd_no' for update in FROM clause

原因:在 MySQL文档中已经详细的指明了该问题。优化器默认会合并 derived table (实际上是一种特殊的subquery,它位于sql语句中FROM子句里面,可以看做是一个单独的表)到外边的查询块,仅当强制具体化 derived table 时,这才有效。

解决方法:前两种比较推荐,不推荐考虑第三种和第四种

包装子查询

update a set status=1 where id in (select * from (select id from a where status is null) as b)

 2、将子查询移动到待更新列表中

update a as A ,(select id from a where status is null) as B set status=1 where A.id = B.id

 optimizer_switch 下的 derived_merge 设置为 off

update  a set status=1 where id in (select id from a where status is null)

直接重写子查询,

来源地址:https://blog.csdn.net/m0_56166876/article/details/127581064

您可能感兴趣的文档:

--结束END--

本文标题: You can‘t specify target table ‘表名‘ for update in FROM clause错误

本文链接: https://www.lsjlt.com/news/402420.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作