Complete the code to select all columns from the table named 'employees'.
SELECT [1] FROM employees;The asterisk (*) selects all columns from the table.
Complete the code to find duplicate employee names in the 'employees' table.
SELECT name, COUNT(*) FROM employees GROUP BY name HAVING COUNT(*) [1] 1;
We use '>' to find names that appear more than once, indicating duplicates.
Fix the error in the query to select unique department names from 'employees'.
SELECT DISTINCT [1] FROM employees;Column names cannot have spaces or dashes unless quoted. 'department_id' is a valid column name.
Fill both blanks to create a query that lists employee names and their department names by joining 'employees' and 'departments'.
SELECT employees.name, departments.[1] FROM employees JOIN departments ON employees.[2] = departments.id;
The department name column is 'dept_name'. The join uses 'department_id' from employees to match 'id' in departments.
Fill all three blanks to write a query that counts employees per department, showing department name and count, only for departments with more than 5 employees.
SELECT departments.[1], COUNT(employees.[2]) FROM employees JOIN departments ON employees.[3] = departments.id GROUP BY departments.[1] HAVING COUNT(employees.[2]) > 5;
We select 'dept_name' from departments, count employee 'id's, and join on 'department_id'.