当前位置:网站首页>【MySQL】mysql:解决[Err] 1093 - You can‘t specify target table ‘表名‘ for update in FROM clause问题
【MySQL】mysql:解决[Err] 1093 - You can‘t specify target table ‘表名‘ for update in FROM clause问题
2022-08-09 08:00:00 【Ctrl练习生-谢哥哥blog】
原始sql
delete from at_phone where id not in(select id from at_phone where id!=1)
运行这段sql语句,结果报错
[Err] 1093 - 您不能在FROM子句中指定目标表“ at_phone”进行更新
原因解决:如果在增删改语句中,要使用子查询的形式进行增删改,那么应该把这个子查询进行第二次select一下并且给上表别名,才可以执行。这个第二次select实际上就是把第一次的select的结果集放在临时表中。
解决后的sql:
delete from at_phone where id not in(select * from (select id from at_phone where id!=1) a)

执行成功
总结
如果觉得不错,可以点赞+收藏或者关注下博主。感谢阅读!
边栏推荐
猜你喜欢
随机推荐
测试流程
引导过程与服务控制
eTS UI开发学习
IO字节流读取文本中文乱码
一文搞懂 条件编译和预处理指令 #define、#undef、#ifdef、#ifndef、#if、#elif、#else、#endif、defined 详解
Shell编程之正则表达式
C: print the diamond
LeetCode: 876. The middle node of the linked list —— simple
【无标题】
CUDA和cuDNN 安装10.0版本
如何把无用的代码注释为 Deprecated 弃用
网络布线及数制转换
HOOPS是什么?这4款3D软件开发工具包你还不知道?
C#基础学习
MySql homework practice questions
Unity 3D模型展示框架篇之资源打包、加载、热更(二)
C language: adjust the order of odd and even numbers
系统安全及应用
Result consisted of more than one row
VMware virtual machine cannot be connected to the Internet after forced shutdown







