PostgreSQL Subquery: Find the name of the employees who are not supervisors
12. Write a SQL subquery to find the first_name and last_name of the employees who are not supervisors.
SELECT b.first_name,b.last_name FROM employees b WHERE NOT EXISTS ( SELECT 'X' FROM employees a WHERE a.manager_id = b.employee_id);
Sample table: employees
pg_exercises=# SELECT b.first_name,b.last_name pg_exercises-# FROM employees b pg_exercises-# WHERE NOT EXISTS ( pg_exercises(# SELECT 'X' pg_exercises(# FROM employees a pg_exercises(# WHERE a.manager_id = b.employee_id); first_name | last_name -------------+------------- Bruce | Ernst David | Austin Valli | Pataballa Diana | Lorentz Alexander | Khoo Shelli | Baida Sigal | Tobias Guy | Himuro Karen | Colmenares Jason | Mallin Michael | Rogers Ki | Gee Hazel | Philtanker Stephen | Stiles John | Seo Joshua | Patel Trenna | Rajs Curtis | Davies Randall | Matos Peter | Vargas Janette | King ... Susan | Mavris Hermann | Baer William | Gietz (88 rows)
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?