首页 > 其他 > 详细

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

时间:2017-07-02 19:38:46      阅读:286      评论:0      收藏:0      [点我收藏+]

 

表中数据:

技术分享

 

执行语句:

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

 

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

原文:http://www.cnblogs.com/fanxuanhui-linux/p/7106847.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!