当前位置:网站首页>mysql delete execution error: You can't specify target table 'doctor_info' for update in FROM clause
mysql delete execution error: You can't specify target table 'doctor_info' for update in FROM clause
2022-08-03 16:02:00 【Mindful little mouse】
for some testing reasons,This led to the appearance of two doctors in the doctor tableID相同的数据,也就是所谓的脏数据,So how to delete the redundant one?
一、First filter out the number of bars greater than1条的:
select doctor_id,count(doctor_id) from `doctor_info` where `scale_group_id`="31" group by doctor_id having count(doctor_id)>1
二、Decided to delete that one?max/min
1、max
select max(id) as id from doctor_group_permission where `scale_group_id`="24120868141551631" group by doctor_id having count(doctor_id)>1
2、min
select min(id) as id from doctor_group_permission where `scale_group_id`="24120868141551631" group by doctor_id having count(doctor_id)>1
三、The data is filtered out,直接delete 报错了
delete from doctor_info where id in(select max(id) as id from doctor_info where `scale_group_id`="31" group by doctor_id having count(doctor_id)>1)
四、错误说明
不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值.
Borrow a temporary table to deal with it,Front-end time wrote oneupdate的,链接在此
五、正确delete操作 借用临时表a
delete from doctor_info where id in(select a.id from(select max(id) as id from doctor_info where `scale_group_id`="31" group by doctor_id having count(doctor_id)>1) a)
边栏推荐
猜你喜欢
8月份加密市场的三个关键预期 价格虽向北移动?预计仍将处于动荡之中
2021年12月电子学会图形化三级编程题解析含答案:分身术
Yii2安装遇到Loading composer repositories with package information
【899. Ordered Queue】
After the cnpm installation is successful, the prompt is not an internal and external command, nor is it a runnable command solution
16 【过渡 动画】
AI+BI+可视化,Sugar BI架构深度剖析
红蓝对抗经验分享:CS免杀姿势
2021年12月电子学会图形化一级编程题解析含答案:放学
DC-DC 2C (40W/30W) JD6606SX2 power back application
随机推荐
Yii2安装遇到Loading composer repositories with package information
Reptile attention
下午见!2022京东云数据库新品发布会
实习路途:记录给我的第一个实习项目中的困惑
STM32 GPIO LED和蜂鸣器实现【第四天】
Small Tools(4) 整合Seata1.5.2分布式事务
How much does Ark Survival Evolved cost?
不安装运行时运行.NET程序
一通骚操作,我把SQL执行效率提高了10000000倍!
unity用代码生成LightProbeGroup
8月份加密市场的三个关键预期 价格虽向北移动?预计仍将处于动荡之中
生态剧变,电子签名SaaS模式迎来新突破,网络效应加速到来
开源一夏 | 打工人的第25天-曾经的考研人
[Code Hoof Set Novice Village 600 Questions] Define a function as a macro
Convex Optimization of Optimal Power Flow (OPF) in Microgrids and DC Grids (Matlab Code Implementation)
Essentially a database data recovery 】 【 database cannot read data recovery case
JS handwritten call apply bind (detailed) (interview)
leetcode: 899. Ordered Queue [Thinking Question]
NodeJs - cross domain
深入浅出Flask PIN