I am using this query to show all the departments and their managers, including the departemnts with no managers, that’s why I am using left join. Now I need to delete the departements where there is no manager. This is my current query:
select
d.DEPARTMENT_NAME,
concat(e.FIRST_NAME,"",e.LAST_NAME) as NAME,
l.CITY
from locations l
join departments d on d.LOCATION_ID = l.LOCATION_ID
left join employees e on e.DEPARTMENT_ID = d.DEPARTMENT_ID
where city = 'Seattle';
How can I change it?
I assume I need to use a delete command somewhere, but I am not sure where exactly
2
Answers
I used a subquery to select LOCATION_ID from locations for ‘Seattle’, that I used to restrict the deletion to departments in that city.
or