w3resource

SQL Subquery Exercises: Display the city of the employee whose ID 134 and works there

SQL SUBQUERY: Exercise-47 with Solution

From the following tables, write a SQL query to find the city of the employee of ID 134. Return city.

Sample table: locations


Sample table: departments


Sample table: employees


Sample Solution:

SELECT city 
	FROM locations 
		WHERE location_id = 
    (SELECT location_id 
		FROM departments 
			WHERE department_id =
             	(SELECT department_id 
					FROM employees 
						WHERE employee_id=134));

Sample Output:

city
South San Francisco

Pictorial Presentation:

SQL Subqueries Exercises: Display the city of the employee whose ID 134 and works there.

Practice Online


Query Visualization:

Duration:

Query visualization of Display the city of the employee whose ID 134 and works there - Duration

Rows:

Query visualization of Display the city of the employee whose ID 134 and works there - Rows

Cost:

Query visualization of Display the city of the employee whose ID 134 and works there - Cost

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

Previous: From the following tables, write a SQL query to find those employees whose department is located in the city 'London'. Return first name, last name, salary, and department ID.
Next: From the following tables, write a SQL query to find those departments where maximum salary is 7000 and above. The employees worked in those departments have already completed one or more jobs. Return all the fields of the departments.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

How to count occurrences of a column value in SQL?

Input table:

id | age
--------
0  | 25
1  | 25
2  | 23
SELECT age, count(age) 
  FROM Students 
 GROUP by age

Output:

id | age | count
----------------
0  | 25  | 2
1  | 25  | 2
2  | 23  | 1

Ref: https://bit.ly/3zbLPQm