当前位置:网站首页>【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)
执行成功
总结
如果觉得不错,可以点赞+收藏或者关注下博主。感谢阅读!
边栏推荐
猜你喜欢
随机推荐
MySql作业练习题
pc端ncnn搭建与测试
Exclude null values when Oracle limits
[STL]stack与queue
主键id,Snowflake雪花算法,优点:生成有顺序的id,提高数据库的性能
ncnn 推理猫狗识别
VMware虚拟机强制关闭后,无法联网
Cookie and Session Details
pip3 source change to improve speed
nvm安装以及管理多版本node教程
204. Count Primes
“互联网+”大学生创新创业大赛经历
权限(上)
引导过程与服务控制
LeetCode·每日一题·761.特殊的二进制序列·分治
文献检索作业代码
Operations in the database (syntax)
Servlet详解
系统安全及应用
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Visualize、HOOPS Publish