w3resource
SQL exercises

SQL Subquery Exercises: Identify all employees who work in departments located in the United Kingdom

SQL SUBQUERY: Exercise-27 with Solution

Write a query that will identify all employees who work in departments located in the United Kingdom.

Sample table: employees


Sample table: departments


Sample table: locations


Sample table: countries


Sample Solution:

SELECT first_name 
FROM employees 
WHERE department_id IN 
(SELECT department_id 
FROM departments 
WHERE location_id IN 
(SELECT location_id 
FROM locations 
WHERE country_id = 
(SELECT country_id 
FROM countries 
WHERE country_name='United Kingdom')));

Sample Output:

first_name
Susan

Practice Online


Query Visualization:

Duration:

Query visualization of Identify all employees who work in departments located in the United Kingdom - Duration

Rows:

Query visualization of Identify all employees who work in departments located in the United Kingdom - Rows

Cost:

Query visualization of Identify all employees who work in departments located in the United Kingdom - Cost

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

Previous: Write a subquery that returns a set of rows to find all departments that do actually have one or more employees assigned to them.
Next: Write a query to identify all the employees who earn more than the average and who work in any of the IT departments.

What is the difficulty level of this exercise?



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