zoukankan      html  css  js  c++  java
  • 从表中删除雇员名字相同的员工记录(需要最少保留一条记录)

    表中数据:

    执行语句:

    mysql> delete from emp where empNO not in (select min(empNO) from emp group by ename);
    ERROR 1093 (HY000): You can't specify target table 'emp' for update in FROM clause

    MySQL出现You can’t specify target table for update in FROM clause
    这个错误的意思是不能在同一个sql语句中,先select同一个表的某些值,
    然后再update这个表。
    这个错误在oracle中不会出现!


    修改语句后执行:OK
    delete from emp where empNO not in
    (
    select *
    from
    (
    select min(empNO)
    from emp
    group by ename
    )
    a);

  • 相关阅读:
    装饰者模式
    代理模式
    享元模式
    模板模式
    命令模式
    建造者模式
    单例模式
    观察者模式
    迭代器模式
    访问者模式
  • 原文地址:https://www.cnblogs.com/fanxuanhui-linux/p/7106847.html
Copyright © 2011-2022 走看看