PostgreSQL Subquery: Find the name of the employees who are managers

4. Write a SQL subquery to find the first_name and last_name of the employees who are working as a manager.

Sample Solution:


SELECT first_name, last_name 
FROM employees 
WHERE (employee_id 
IN (SELECT manager_id 
FROM employees));

Sample table: employees


pg_exercises=# SELECT first_name, last_name
pg_exercises-# FROM employees
pg_exercises-# WHERE (employee_id
pg_exercises(# IN (SELECT manager_id
pg_exercises(# FROM employees));

 first_name | last_name
 Alexander  | Hunold
 Den        | Raphaely
 Steven     | King
 Neena      | Kochhar
 Payam      | Kaufling
 Shanta     | Vollman
 Kevin      | Mourgos
 John       | Russell
 Karen      | Partners
 Alberto    | Errazuriz
 Gerald     | Cambrault
 Eleni      | Zlotkey
 Lex        | De Haan
 Matthew    | Weiss
 Adam       | Fripp
 Nancy      | Greenberg
 Michael    | Hartstein
 Shelley    | Higgins
(18 rows)

Practice Online

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

New Content: Composer: Dependency manager for PHP, R Programming