mysql修改删除You can't specify target table for update in FROM clause的问题
表中出现重复数据,需要删除重复数据,只保留一条
DELETE
FROM
crm_participant
WHERE
id IN (
SELECT
c.id cid
FROM
crm_participant c
WHERE
c.parentPhone IN ( SELECT a.parentPhone FROM crm_participant a GROUP BY a.parentPhone HAVING count( a.parentPhone ) > 1 )
AND c.id NOT IN ( SELECT min( b.id ) FROM crm_participant b GROUP BY b.parentPhone HAVING count( b.parentPhone ) > 1 )
ORDER BY
c.parentPhone
) 错误信息:
> 1093 - You can't specify target table 'crm_participant' for update in FROM clause
> 时间: 0.005s
问题分细:
mysql不允许对同一个表中查出来的数据作为条件,在执行跟新操作。 在一条 sql 语句中不能先查出来部分内容,再同时又对当前表作修改。
解决办法:这个是正确的sql,其实就是对上边的红色部分的查询sql进行了一层包裹。让查询出来的信息被一个 select 包裹一下,然后作为条件就可以了 DELETE
FROM
crm_participant
WHERE
id IN (
SELECT
v.cid
FROM
(
SELECT
c.id cid
FROM
crm_participant c
WHERE
c.parentPhone IN ( SELECT a.parentPhone FROM crm_participant a GROUP BY a.parentPhone HAVING count( a.parentPhone ) > 1 )
AND c.id NOT IN ( SELECT min( b.id ) FROM crm_participant b GROUP BY b.parentPhone HAVING count( b.parentPhone ) > 1 )
ORDER BY
c.parentPhone
) v
)
mysql修改删除You can't specify target table for update in FROM clause的问题的更多相关文章
- MYSQL 1093 之You can't specify target table for update in FROM clause解决办法
You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 出现以上错误,是因为想将表自身的字 ...
- mysql错误:1093-You can’t specify target table for update in FROM clause的解决方法
update语句中包含的子查询的表和update的表为同一张表时,报错:1093-You can’t specify target table for update in FROM clause my ...
- MYSQL错误:You can't specify target table for update in FROM clause
这句话意思是:不能先select再更新(修改)同一个表. 可以再外嵌套多一层,这个问题只有mysql有,mssql和oracle都没有. # 出错delete from Person where Id ...
- mysql中You can't specify target table for update in FROM clause
使用mysql在删除表中重复记录 delete from user where username in (select user name form(select username from user ...
- MySQL之You can't specify target table for update in FROM clause解决办法
这篇文章主要介绍了mysql中You can't specify target table for update in FROM clause错误解决方法,需要的朋友可以参考下 MySQL中You c ...
- MYSQL之You can't specify target table for update in FROM clause解决办法
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...
- mysql出现You can’t specify target table for update in FROM clause
在mysql执行下面语句时报错: You can’t specify target table for update in FROM clause UPDATE edu_grade_hgm_1 ' W ...
- 解决mysql You can't specify target table for update in FROM clause错误
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...
- mysql中You can’t specify target table for update in FROM clause错误解决方法
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...
随机推荐
- XML二
XML的语法要求: 1,XML文档必须有一个顶层元素,即文档元素,所有其他元素必须嵌入在文档元素中. 2,元素嵌套要正确,即如果一个元素在另一个元素中开始,那么必须在同一个元素中结束. 3,每个元素必 ...
- springboot2.1.3.RELEASE+jsp笔记war部署tomcat
springboot+jsp <packaging>war</packaging> <parent> <groupId>org.springframew ...
- linux环境下安装nginx步骤(不错)
开始前,请确认gcc g++开发类库是否装好,默认已经安装. ububtu平台编译环境可以使用以下指令 apt-get install build-essential apt-get install ...
- 简单的shell脚本练习(一)
1:求1000一内的偶数和 方法一: #!/bin/bash #用累加实现1000以内的偶数和 sum= ;i<=;i=i+)) do sum=$(($sum+$i)); done echo $ ...
- Linux内核分析第二次作业
这周学习了<庖丁解牛Linux内核分析>并且学习了实验楼的相关知识. 在实验楼的虚拟环境下编写代码: 通过gcc编译后,使用查看文件命令:cat -n 20189223.c 在vim中, ...
- C# 数据库
连接: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- ueditor的简单用法
先粘贴未使用ueditor之前的代码: <body> <label for="input_content">作答区:</label> <t ...
- STM32定时器时间的计算方法
本文出自:https://wenku.baidu.com/view/e3bdfb7601f69e31433294c4.htmlSTM32定时器时间的计算方法STM32中的定时器有很多用法:(一)系统时 ...
- G1回收算法
待完善...... 参考: https://mp.weixin.qq.com/s?__biz=MzIxMjE5MTE1Nw==&mid=2653193390&idx=2&sn= ...
- [UE4]Input Key Selector
一.Input Key Selector:按键设置 二.On Key Selected:按键收集完毕后触发该事件. 三.点击On Key Selected控件后,会显示“...”,表示可以接受键盘输入 ...