w3resource
SQL exercises

SQL Subquery Exercises: Display the full name of manager who is supervising 4 or more employees

SQL SUBQUERY: Exercise-50 with Solution

Write a query in SQL to display the full name (first and last name) of manager who is supervising 4 or more employees.

Sample table: employees


Sample Solution:

SELECT first_name || \' \' || last_name AS Manager_name,department_id
	FROM employees 
		WHERE employee_id IN 
		(SELECT manager_id 
		FROM employees 
			GROUP BY manager_id 
			HAVING COUNT(*)>=4);

Sample Output:

manager_name	department_id
Steven King		90
Neena Kochhar		90
Alexander Hunold	60
Nancy Greenberg		100
Den Raphaely		30
Matthew Weiss		50
Adam Fripp		50
Payam Kaufling		50
Shanta Vollman		50
Kevin Mourgos		50
John Russell		80
Karen Partners		80
Alberto Errazuriz	80
Gerald Cambrault	80
Eleni Zlotkey		80

Practice Online


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

Previous: Write a query in SQL to display the detail information of those departments which starting salary is at least 8000.
Next: Write a query in SQL to display the details of the current job for those employees who worked as a Sales Representative in the past.

What is the difficulty level of this exercise?



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