Reputation: 63
I am trying to return the branches which have no manager.
And this is what I tried:
SELECT branchno, city FROM branch
WHERE branchno IN
(SELECT branchno FROM STAFF
WHERE position <> 'Manager');
And it returns:
branchno | city
----------+----------
B005 | London
B007 | Aberdeen
B003 | Glasgow
(3 rows)
Upvotes: 0
Views: 129
Reputation: 77896
There are many ways, you can use WHERE NOT EXISTS
like below. BTW, your posted query should as well give you the desired result (per your post title). What else you are looking for?
SELECT b.branchno, b.city
FROM branch b
WHERE NOT EXISTS
(SELECT 1 FROM STAFF WHERE branchno = b.branchno
AND position = 'Manager');
Upvotes: 1
Reputation: 39507
You can easily do this using not in
select *
from branch
where branchno not in (
select branchno from staff
where position = 'Manager'
);
Upvotes: 1