当前位置:网站首页>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)
边栏推荐
- 土耳其国防部:联合协调中心将对首艘乌克兰粮船进行安全检查
- 劲爆!协程终于来了!线程即将是过去式
- 为教育插上数字化的翅膀,网易云信发布「互联网+教育」整体解决方案
- 用户侧有什么办法可以自检hologres单表占用内存具体是元数据、计算、缓存的使用情况?
- Neural networks, cool?
- AWS中国区SDN Connector
- [Code Hoof Set Novice Village 600 Questions] Define a function as a macro
- 力扣1206. 设计跳表--SkipList跳表是怎么跳的?
- Windows服务器如何防止黑客入侵的安全设置
- Essentially a database data recovery 】 【 database cannot read data recovery case
猜你喜欢

Ark server open tool, server tutorial win

指令重排以及案例

实习路途:记录给我的第一个实习项目中的困惑

2021年12月电子学会图形化三级编程题解析含答案:数星星

并发编程的核心问题

新一代网状网协议T-Mesh无线通信技术优势介绍

【Unity入门计划】基本概念(8)-瓦片地图 TileMap 01

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

Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)

红蓝对抗经验分享:CS免杀姿势
随机推荐
方舟开服工具、服务器教程win
全新探险者以40万的产品击穿豪华SUV价格壁垒
ReentrantLock详解
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
STM32 GPIO LED和蜂鸣器实现【第四天】
JS手写call apply bind (详细)(面试)
[微信小程序开发者工具] × #initialize
MATLAB gcf figure save image with black background/transparent background
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
Small Tools(4) 整合Seata1.5.2分布式事务
30W 2C(JD6606S + FP6652X2)BOM
基于DMS的数仓智能运维服务,知多少?
DC-DC 2C (40W/30W) JD6606SX2 power back application
MySQL中的基数是啥?
Go Go 简单的很,标准库之 fmt 包的一键入门
ECCV 2022 | Relational Query-Based Temporal Action Detection Methods
袁小林:沃尔沃专注于出行的安全感,并且把它做到极致
高压直流输电(HVDC)的最优潮流(OPF)(Matlab代码实现)
如何启动 NFT 集合