Skip to content

Instantly share code, notes, and snippets.

@arbaieffendi
Created May 15, 2019 09:11
Show Gist options
  • Save arbaieffendi/49f9a206e1b4c9ffccb848dc42c62de3 to your computer and use it in GitHub Desktop.
Save arbaieffendi/49f9a206e1b4c9ffccb848dc42c62de3 to your computer and use it in GitHub Desktop.
Write a query that selects the names of employees who are not managers.
SELECT name
FROM employees
WHERE id
NOT IN (SELECT managerId FROM employees WHERE managerId IS NOT null)
@anua24060
Copy link

Very helpful!

@NeO5389
Copy link

NeO5389 commented Dec 4, 2022

please someone tell me why this doesn't work?
SELECT name
FROM employees
WHERE id
NOT IN (SELECT DISTINCT(managerId) FROM employees)

@nrk7955
Copy link

nrk7955 commented Mar 26, 2023

select e.name
from employees as e
left join employees as m
on e.id = m.managerId
where m.managerId is null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment