Reputation: 127
I have to tables as follows;
I would like to select every item from the 'Employers' table where 'Job Title' does NOT show up in the 'Employees' table.
I know this is a simple query but it has me stumped. I'd be grateful for any help. Thanks.
Upvotes: 1
Views: 66
Reputation: 1713
select * from employers
where jobtitle not in (select jobtitle
from employees
where jobtitle is not null);
I would consider having a jobs table with foreign keys to both employees and employers
edit - thanks all for the not null fix
Upvotes: 1
Reputation: 238068
You could use a join:
select *
from employers
left join (
select distinct jobtile
from employees
) emp on employers.jobtitle = emp.jobtitle
where emp.jobtitle is null
Itchi's approach is more readable, but don't forget an where jobtitle is not null
at the end of the subquery :)
Upvotes: 0