文章目录

  • 1. 复现错误
  • 2. 分析错误
  • 3. 解决错误

1. 复现错误

今天在工作时,接到一个新需求,就是将app_page_button表中的label_code字段修改为edit,条件如下:

  1. 只更新值为nulllabel_code

  2. 且以/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的错误相关推荐

  1. [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 ...

  2. 记录一个多表查询的问题 #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 ...

  3. 【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 错误的 ...

  4. 解决——》[Err] 1093 - You can't specify target table 'fcf' for update in FROM clause

    版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者. https://blog.csdn.net/weixin_43453386/article/detai ...

  5. [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 ...

  6. 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); 会报出错 ...

  7. 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 ...

  8. 错误: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 ...

  9. 【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, ...

最新文章

  1. jQuery 遍历 - closest() 方法
  2. python画图横轴刻度间隔设置为3个月_Python 天气情况数据分析及可视化
  3. 【KMP模板】简单写个KMP~
  4. server2003-多域间林之间信任配置方法详解(附图)
  5. 为制造业构建Teams Power App 1:Dataverse入门
  6. 【缩点】洛谷P3387
  7. 【BearChild】
  8. matlab里impz指令格式,华北电力大学Matla实验指导书.doc
  9. Rais 实现单点登录SSO
  10. 嵌入式—LM3S1138介绍
  11. 支付宝,微信,线上支付流程介绍
  12. 实际案例说明计算机网络安全,计算机网络安全案例教程
  13. kcl方程独立性的图论证明
  14. IDEA打开Maven项目一直indexing或 scanning files to index导致整个idea页面卡住 解决方法
  15. 数据预处理与特征工程—12.常见的数据预处理与特征工程手段总结
  16. 美国亚马逊图片打不开
  17. CardView(墨客)
  18. 近日学习笔记:df -h和du -sh命令,查看linux版本,vbm管理工具,su命令,ssh服务升级技巧,source命令
  19. VOS3000在使用过程中如何快速有效地排查出现的问题
  20. 最全Pycharm教程(13)——Pycharm部署

热门文章

  1. AJAX原理快速入门
  2. Plant, Cell Environment:DAP-seq技术在ZmEREB57调控OPDA合成提高玉米耐盐性研究中的应用
  3. 代码随想录算法训练营day6| 454.四数相加II 383.赎金信 15.三数之和 18.四数之和
  4. 在卓越网上买了几本书
  5. BannerStudio---旗帜软件工作室2021年交接会会议总结
  6. @Html.ValidationSummary() 的作用 --MVC笔记
  7. 通话耳机怎么挑选、2022值得入手的六款蓝牙耳机排名
  8. python高并发编程_Python——并发编程
  9. 更换参数长度为零_图们水稳拌合机械机械参数 - 图们机械及行业设备
  10. 矩阵和稀疏矩阵相互转化(数组方式实现)