• 从表中删除雇员名字相同的员工记录(需要最少保留一条记录)


    表中数据:

    执行语句:

    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);

  • 相关阅读:
    JavaSE_11_File类、递归
    JavaSE_10_IO流
    leyou_07_对数据的操作
    JavaSE_09_Map
    JavaSE_08_Collections常用功能
    java 22
    java 22
    java 22
    java 22
    java 22
  • 原文地址:https://www.cnblogs.com/fanxuanhui-linux/p/7106847.html
Copyright © 2020-2023  润新知