全网详细解决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, ...
最新文章
- 昨天,JetBrains 推出“下一代 IDE”,快看有哪些值得期待的功能!
- 使用流光法实现物体跟踪
- 线性代数学习笔记(几何版)
- lazada开店流程图解,及平台类目佣金分享!
- Linux定时任务服务crond
- android 怎么初始化下拉框_第30讲:“二师兄”的成长历程之二,类属性的初始化...
- 第7章 C控制语句:分支和跳转
- 如何通过VC的 CHttpFile 抓取网页内容
- 为什么我使用Java
- 动态规划——打家劫舍(Leetcode 198)
- SQL Server 2008 各种DateTime的取值范围
- 枚举类 enum,结构体类 struct
- 微设计(www.weidesigner.com)介绍系列文章(三)
- 2017 计蒜之道 初赛 第五场 A. UCloud 机房的网络搭建
- 栅栏密码--Python解密脚本
- 虚拟仿真实验项目所需服务器,工程结构虚拟仿真实验室
- 解构语音交互产品--人工智能AI技术
- Initialization of variable was never used; consider replacing with assignment to ‘_’ or removing it
- 电脑重新分区后文件怎么恢复?流水的难题铁打的办法
- python中多重if语句用法_python-循环语句的简单条件语句、多重条件语句和嵌套条件语句编写...