SQL Subquery Exercises: Display a set of rows to find all departments that do actually have one or more employees assigned to them
SQL SUBQUERY: Exercise-26 with Solution
Write a subquery that returns a set of rows to find all departments that do actually have one or more employees assigned to them.
Sample table: employees
Sample table: departments
SELECT department_name FROM departments WHERE department_id IN (SELECT DISTINCT(department_id) FROM employees);
department_name Administration Marketing Purchasing Human Resources Shipping IT Public Relations Sales Executive Finance Accounting
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query to display the employee id, name ( first name and last name ), SalaryDrawn, AvgCompare (salary - the average salary of all employees) and the SalaryStatus column with a title HIGH and LOW respectively for those employees whose salary is more than and less than the average salary of all employees.
Next: Write a query that will identify all employees who work in departments located in the United Kingdom.
What is the difficulty level of this exercise?