表中数据:

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

 

执行语句:

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

 

相关文章:

  • 2022-02-04
  • 2021-11-23
  • 2021-07-14
  • 2021-09-03
  • 2022-12-23
  • 2021-08-31
  • 2021-07-15
猜你喜欢
  • 2022-02-12
  • 2022-01-27
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
相关资源
相似解决方案