表中出现重复数据,需要删除重复数据,只保留一条

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的问题的更多相关文章

  1. MYSQL 1093 之You can't specify target table for update in FROM clause解决办法

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 出现以上错误,是因为想将表自身的字 ...

  2. 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 ...

  3. MYSQL错误:You can't specify target table for update in FROM clause

    这句话意思是:不能先select再更新(修改)同一个表. 可以再外嵌套多一层,这个问题只有mysql有,mssql和oracle都没有. # 出错delete from Person where Id ...

  4. 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 ...

  5. 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 ...

  6. 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这个表( ...

  7. 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 ...

  8. 解决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这个表( ...

  9. 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这个表( ...

随机推荐

  1. PTA——完全数

    PTA 7-45 找完数 网友“云上明月”的程序: #include<stdio.h> int isPerfect(int num); int main() { ; int maxFact ...

  2. 第2章 Java基本语法(上): 变量与运算符

    2-1 关键字与保留字 关键字(keyword) 保留字(reserved word) 2-2 标识符(Identifier) 案例 class Test{ public static void ma ...

  3. fullCalendar使用经验总结

    fullCalendar日历控件官方网址: https://fullcalendar.io/ 1.需要引入的文件 <link href="~/assets/fullcalendar-3 ...

  4. Java面试题 OOAD & UML+XML+SQL+JDBC & Hibernate

    二.OOA/D 与UML 部分:(共6 题:基础2 道,中等难度4 道) 96.UML 是什么?常用的几种图?[基础] 答:UML 是标准建模语言:常用图包括:用例图,静态图(包括类图.对象图和包图) ...

  5. Linux platform平台总线、平台设备、平台驱动

    平台总线(platform_bus)的需求来源? 随着soc的升级,S3C2440->S3C6410->S5PV210->4412,以前的程序就得重新写一遍,做着大量的重复工作, 人 ...

  6. 使用pageoffice进行多个文档的合并

    提前给test模板文件中 手动插入一个书签,因为pageoffice必须有一个书签后,才能在后台进行书签的创建 //多个word文件进行合并 string strCopyFolder = System ...

  7. IIS6.0+win2003部署MVC网站的一些问题

    安装iis,framework环境不谈.MVC网站部署 步骤: 1.为程序新建一个应用程序池(将default的那个程序池作为模板就可以了) 2.web服务扩展一些启用一些必要的服务 3.新建网站 描 ...

  8. if else和switch case那个效率更高一点

    switch...case写法: switch (表达式){ case 值1 : 语句1 break; case 值2 : 语句2 break; ... default : 语句n break; } ...

  9. 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) ...ubuntu 18.04 安装vim遇到的错误

    安装vim: sudo apt-get install vim-gtk 问题: E:无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用) E:无法锁定管理目录(/ ...

  10. c# HashTable (哈希表)

    HashTable 哈希表 也是System.Collections集合下的数据结构类 它储存的也是Object类型的对象 但是它在内存中是散列排布的 因为这个特性,非常适合存储大量的数据 在Hash ...