【发布时间】:2022-01-29 06:02:12
【问题描述】:
delete from emploee_id where id not in(select max(id) from emploee_id group by name,dept,salary,experience);
在运行此查询时,错误显示如下
“错误代码:1093。您不能为目标表'emploee_id'指定 在 FROM 子句中更新"
请有人帮帮我
【问题讨论】:
delete from emploee_id where id not in(select max(id) from emploee_id group by name,dept,salary,experience);
在运行此查询时,错误显示如下
“错误代码:1093。您不能为目标表'emploee_id'指定 在 FROM 子句中更新"
请有人帮帮我
【问题讨论】:
您可以改为对临时表执行 JOIN
delete e
from emploee_id e
left join
(
select select max(id) as id
from emploee_id
group by name, dept, salary, experience
) tmp on tmp.id = e.id
where tmp.id is null
【讨论】:
您不能在子查询中使用同一个表。尝试使用 SET @variable_name = select max(id) from emploee_id group by name,dept,salary,experience作为单独的查询,并在变量中设置其值。 然后在 delete query delete from emploee_id where id=@variable_name
中使用该值【讨论】:
"delete from emploee_id where id not in(select max(id) from emploee_id group by name,dept,salary,experience); "
实际上没有目标,该 select 语句中应该有一个 where 子句 例子
"delete from emploee_id where id not in(select max(id) from emploee_id **where** group by name,dept,salary,experience); "
我真的认为您再次查看 sql 选择的代码并确定您要查询的内容
【讨论】: