PostgreSQL Subquery: Find the names of the employees who works in the IT department

2. Write a SQL subquery to find the first_name and last_name of all employees who works in the IT department.

Sample Solution:


SELECT first_name, last_name 
FROM employees 
WHERE department_id 
IN (SELECT department_id 
FROM departments 
WHERE department_name='IT');

Sample table: employees


pg_exercises=# SELECT first_name, last_name
pg_exercises-# FROM employees
pg_exercises-# WHERE department_id
pg_exercises-# IN (SELECT department_id
pg_exercises(# FROM departments
pg_exercises(# WHERE department_name='IT');
 first_name | last_name
 Alexander  | Hunold
 Bruce      | Ernst
 David      | Austin
 Valli      | Pataballa
 Diana      | Lorentz
(5 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