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

论坛 期权论坛 脚本     
匿名技术用户   2021-1-5 08:52   11   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);

转载于:https://www.cnblogs.com/fanxuanhui-linux/p/7106847.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP