当前位置:网站首页>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)
边栏推荐
猜你喜欢

Ark server open tool, server tutorial win

With a single operation, I improved the SQL execution efficiency by 10,000,000 times!

Research on power flow in DC microgrid based on Newton's method (Matlab code implementation)

Basic knowledge points in js - events

一个文件管理系统的软硬件配置清单

A new round of competition for speech recognition has started. Will natural dialogue be the next commanding height?

MATLAB gcf figure save image with black background/transparent background

如何分析周活跃率?
![[微信小程序开发者工具] × #initialize](/img/38/ea90525f53de3933a808f0d75028b0.png)
[微信小程序开发者工具] × #initialize

16 【过渡 动画】
随机推荐
随笔-Unity中一个简易的Spine动画控制器
基于DMS的数仓智能运维服务,知多少?
新一代网状网协议T-Mesh无线通信技术优势介绍
Reptile attention
49 万奖金等你来拿!第四届实时计算 Flink 挑战赛启动,Beyond Stream Processing!
Three key expectations for the crypto market in August Price moves north?Still expected to be in turmoil
JS basics--judgment
2021年12月电子学会图形化三级编程题解析含答案:跳高比赛
Ruoyi Ruoyi framework @DataScope annotation use and some problems encountered
【QT】Qt项目demo:数据在ui界面上显示,鼠标双击可弹窗显示具体信息
8月份加密市场的三个关键预期 价格虽向北移动?预计仍将处于动荡之中
分享一款免费OPC UA服务器
泰山OFFICE技术讲座:段落边框的绘制难点在哪里?
请问下阿里云全托管flink能执行两条flink sql命令么?
How Navicat connects to MySQL on a remote server
posgresql 到 es 报这个错误 ,啥意思
破解数字化转型困局,企业分析协同场景案例解析
出海季,互联网出海锦囊之本地化
The general trend, another key industry related to Sino-US competition, has reached a critical moment
新版本的 MaxCompute 中,SQL支持的 LIMIT OFFSET 的语法是什么功能?