全网详细解决1093 - You can‘t specify target table ‘xxx‘ for update in FROM clause的错误
文章目录
- 1. 复现错误
- 2. 分析错误
- 3. 解决错误
1. 复现错误
今天在工作时,接到一个新需求,就是将app_page_button
表中的label_code
字段修改为edit
,条件如下:
只更新值为
null
的label_code
且以
/edit/${id}'
结尾的option_value
首先使用如下SQL
查询满足上述条件的记录,如下代码所示:
SELECT id, label, label_code, option_value
FROM app_page_button
WHERE label_code IS NULL AND option_value LIKE '%/edit/${id}';+-----+-------+------------+-----------------------+
| id | label | label_code | option_value |
+-----+-------+------------+-----------------------+
| 706 | 编辑 | NULL | put:common/edit/${id} |
| 710 | 编辑 | NULL | put:common/edit/${id} |
| 714 | 编辑 | NULL | put:common/edit/${id} |
+-----+-------+------------+-----------------------+
得到满足上述条件的记录有3条
,使用如下SQL
语句修改:
UPDATE app_page_button
SET label_code = 'edit'
WHEREid IN ( SELECT id FROM app_page_button WHERE label_code IS NULL AND option_value LIKE '%/edit/${id}' );ERROR 1093 (HY000): You can't specify target table 'app_page_button' for update in FROM clause
即You can't specify target table 'app_page_button' for update in FROM clause
的错误。
2. 分析错误
最近申请的文心一言刚审核通过,可以借助它来分析我的错误,如下图所示:
文心一言的回答,和我的本意不一致。我本想在查询结果中,更新label_code
值。
因而,我需要自己分析,来解决这个错误。
You can't specify target table 'app_page_button' for update in FROM clause
的含义:不能在同一表(app_page_button
)中查询的数据,作为同一表(app_page_button
)的更新数据。
3. 解决错误
既然不能先select
出同一表中的某些值,再update
这个表(在同一语句中),那就采用将查询结果存储到临时表(tmp
)表中,id
从这个临时表(tmp
)中获取,如下代码所示:
UPDATE app_page_button
SET label_code = 'edit'
WHEREid IN ( SELECT id FROM ( SELECT id FROM app_page_button WHERE label_code IS NULL AND option_value LIKE '%/edit/${id}' ) as tmp );Query OK, 3 rows affected (0.01 sec)
Rows matched: 3 Changed: 3 Warnings: 0
根据Query OK, 3 rows affected (0.01 sec)
这句话可知,已更新成功,从如下SQL可以看到:
select id, label, label_code, option_value
from app_page_button
where id in (706,710,714);+-----+-------+------------+-----------------------+
| id | label | label_code | option_value |
+-----+-------+------------+-----------------------+
| 706 | 编辑 | edit | put:common/edit/${id} |
| 710 | 编辑 | edit | put:common/edit/${id} |
| 714 | 编辑 | edit | put:common/edit/${id} |
+-----+-------+------------+-----------------------+
3 rows in set (0.00 sec)
全网详细解决1093 - You can‘t specify target table ‘xxx‘ for update in FROM clause的错误相关推荐
- [Err] 1093 - You can't specify target table 'xxx' for update in FROM clause解决方法
执行开发同学提供的删除数据的sql时报错[Err] 1093 - You can't specify target table 'run_result' for update in FROM clau ...
- 记录一个多表查询的问题 #1093 - You can‘t specify target table ‘xxx‘ for update in FROM clause
SQL里面,多表查询比较常见,用法也比较简单 可以是 SELECT ood.oodId, ood.status, ood.userId, orders.createdAt FROM ood, orde ...
- 【MySQL】Error Code: 1093. You can‘t specify target table ‘xxx‘ for update in FROM clause
1. 报错信息: Error Code: 1093. You can't specify target table 'self_check' for update in FROM clause 错误的 ...
- 解决——》[Err] 1093 - You can't specify target table 'fcf' for update in FROM clause
版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者. https://blog.csdn.net/weixin_43453386/article/detai ...
- [Err] 1093 - You can't specify target table 's' for update in FROM clause
[Err] 1093 - You can't specify target table 's' for update in FROM clause 执行SQL DELETE from book WHE ...
- MySQL [1093] You can‘t specify target table ‘titles_test‘ for update in FROM clause
执行以下语句: delete from titles_test where id not in(select min(id)from titles_testgroup by emp_no); 会报出错 ...
- MySQL 语法问题:You can‘t specify target table ‘xxx‘ for update in FROM clause. 原因及解决方法
报错信息如下: [Code: 1093, SQL State: HY000] You can't specify target table 'bd_bankaccbas' for update in ...
- 错误:You can't specify target table 'xxx' for update in FROM clause的解决
今天在MySQL数据库删除重复数据的时候遇到了一个问题.如下脚本: DELETE FROM tempA WHERE tid IN ( SELECT MAX(tid) AS tid FROM tempA ...
- 【mysql 】sql错误代码 1093 You cannot specify target table xxxx for update in FROM clause
在mysql8.X中执行如下语句: DELETE FROM`test`.unsign_wocode WHEREid IN (SELECTa.id FROM`test`.unsign_wocode a, ...
最新文章
- jQuery 遍历 - closest() 方法
- python画图横轴刻度间隔设置为3个月_Python 天气情况数据分析及可视化
- 【KMP模板】简单写个KMP~
- server2003-多域间林之间信任配置方法详解(附图)
- 为制造业构建Teams Power App 1:Dataverse入门
- 【缩点】洛谷P3387
- 【BearChild】
- matlab里impz指令格式,华北电力大学Matla实验指导书.doc
- Rais 实现单点登录SSO
- 嵌入式—LM3S1138介绍
- 支付宝,微信,线上支付流程介绍
- 实际案例说明计算机网络安全,计算机网络安全案例教程
- kcl方程独立性的图论证明
- IDEA打开Maven项目一直indexing或 scanning files to index导致整个idea页面卡住 解决方法
- 数据预处理与特征工程—12.常见的数据预处理与特征工程手段总结
- 美国亚马逊图片打不开
- CardView(墨客)
- 近日学习笔记:df -h和du -sh命令,查看linux版本,vbm管理工具,su命令,ssh服务升级技巧,source命令
- VOS3000在使用过程中如何快速有效地排查出现的问题
- 最全Pycharm教程(13)——Pycharm部署
热门文章
- AJAX原理快速入门
- Plant, Cell Environment:DAP-seq技术在ZmEREB57调控OPDA合成提高玉米耐盐性研究中的应用
- 代码随想录算法训练营day6| 454.四数相加II 383.赎金信 15.三数之和 18.四数之和
- 在卓越网上买了几本书
- BannerStudio---旗帜软件工作室2021年交接会会议总结
- @Html.ValidationSummary() 的作用 --MVC笔记
- 通话耳机怎么挑选、2022值得入手的六款蓝牙耳机排名
- python高并发编程_Python——并发编程
- 更换参数长度为零_图们水稳拌合机械机械参数 - 图们机械及行业设备
- 矩阵和稀疏矩阵相互转化(数组方式实现)