mysql - 如何从员工表中删除最高薪员工?
问题描述
Employee表由Employee_id、Employee name和salary组成
如何从员工表中删除薪酬最高的员工?我试过了
delete from employee
where salary = (select max(salary) from employee);
但它给出了一个错误;
错误代码:1093。您无法在 FROM 子句 0.0022 秒中指定目标表“员工”进行更新
解决方案
你可以简单地做
delete from employee
order by salary desc
limit 1
或修复您的查询
delete from employee
where salary in
(
select * from (select max(salary) from employee) x
)
因为您需要构建一个临时表作为解决方法,因为您从同一个表中选择和删除。