w3resource

SQL Subquery Exercises: Display the details of departments managed by Susan

SQL SUBQUERY: Exercise-53 with Solution

From the following table, write a SQL query to find the departments managed by Susan. Return all the fields of departments.

Sample table : departments


Sample table: employees


Sample Solution:

SELECT * 
	FROM departments 
	WHERE manager_id IN 
	(SELECT employee_id 
		FROM employees 
			WHERE first_name='Susan');

Sample Output:

department_id	department_name	manager_id	location_id
40		Human Resources	203 		2400

Pictorial Presentation:

SQL Subqueries Exercises: Display the details of departments managed by Susan.

Practice Online


Query Visualization:

Duration:

Query visualization of Display the details of departments managed by Susan - Duration

Rows:

Query visualization of Display the details of departments managed by Susan - Rows

Cost:

Query visualization of Display the details of departments managed by Susan - Cost

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

Previous: From the following table, write a SQL query to find those employees who earn second-lowest salary of all the employees. Return all the fields of employees.
Next: From the following table, write a SQL query to find those employees who earn highest salary in a department. Return department ID, employee name, and salary.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

"where 1=1" statement?

It's usually when folks build up SQL statements.

When you add and value = "Toyota" you don't have to worry about whether there is a condition before or just WHERE.

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