Complete the code to select all employees who work in the 'Sales' department using a subquery.
SELECT name FROM employees WHERE department_id = (SELECT [1] FROM departments WHERE name = 'Sales');
The subquery must return the department's id to match with employees' department_id.
Complete the code to join employees with departments to get employee names and their department names.
SELECT employees.name, departments.[1] FROM employees JOIN departments ON employees.department_id = departments.id;We want to select the name of the department to show alongside employee names.
Fix the error in the subquery to find employees with salary greater than the average salary.
SELECT name FROM employees WHERE salary > (SELECT [1](salary) FROM employees);The query needs the average salary, so the function AVG is correct.
Fill both blanks to write a JOIN that selects employee names and their manager names.
SELECT e.name AS employee, m.[1] AS manager FROM employees e JOIN employees m ON e.[2] = m.id;
The manager's name is selected, and employees' manager_id links to managers' id.
Fill all three blanks to write a subquery that finds departments with more than 5 employees.
SELECT name FROM departments WHERE id IN (SELECT [1] FROM employees GROUP BY [2] HAVING COUNT([3]) > 5);
The subquery selects department_id from employees, groups by it, and counts all rows with * to find departments with more than 5 employees.