I would like to retrieve the names of people who didn\'t work on a project in PostgreSQL.
I got a table named employees
with their names
and
This is easy with NOT IN
:
select * from employees
where ssn not in (select ssn from works_on)
Alternative with LEFT JOIN
:
SELECT fname,lname
FROM employee w
LEFT JOIN works_on wa
ON (wa.ssn = w.ssn)
WHERE wa.ssn IS NULL
This alternative is useful as you sometimes have more complicated requirements that can't easily be expressed with IN
or EXISTS
.