我有以下查询:
delete from departments
where department_id = (select department_id
from employees
where salary > 100000);
查询当然返回超过1行,有人知道如何在不执行某项功能或类似内容的情况下删除一个查询中的所有部门?
答案 0 :(得分:7)
使用IN
:
delete from departments
where department_id in (select department_id
from employees
where salary > 100000);
答案 1 :(得分:4)
或者加入他们
DELETE d
FROM departments d
INNER JOIN employees e ON d.department_id = e.department_id
WHERE e.salary > 100000;