当前位置:网站首页>【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)
执行成功
总结
如果觉得不错,可以点赞+收藏或者关注下博主。感谢阅读!
边栏推荐
猜你喜欢
随机推荐
One-click login server script
[STL]list
Shell编程之正则表达式
Selenium测试案例一步步学之(2)Selenium自动测试脚本模块化(下)
VMware virtual machine cannot be connected to the Internet after forced shutdown
三层交换机原理及配置
resourcemanager启动失败,别的节点成功
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
.net(二) 配置数据库
[STL]string
VMware虚拟机强制关闭后,无法联网
CUDA和cuDNN 安装10.0版本
Luogu P1110 report statistics multiset stl good question
可能导致Loadrunner检查点中savecount为0的分析
H3C_利用策略路由实现出口双线路负载(选路)的部署
The String class objects created by the JVM memory allocation and the difference between equals and = =
App testing
种子数据报错:liquibase.exception.ValidationFailedException: Validation Failed
主键id,Snowflake雪花算法,优点:生成有顺序的id,提高数据库的性能
P1064 金明的预算方案