EasyJOINs (INNER, LEFT, RIGHT, FULL)
RIGHT JOIN: show all departments even without employees
The query
SQL
SELECT
d.dept_name,
d.location,
COUNT(e.emp_id) AS employee_count
FROM employees e
RIGHT JOIN departments d ON e.dept_id = d.dept_id
GROUP BY d.dept_id, d.dept_name, d.location
ORDER BY employee_count;Note
“RIGHT JOIN keeps ALL rows from right table. Less common; usually rewritten as LEFT JOIN.