Intermediate-level SQL LEFT JOIN practice exercises with solutions.
Exercise 1
Question: List all employees and their departments, including employees without a department.
SELECT e.name AS employee, d.name AS department FROM employees e LEFT JOIN departments d ON e.department_id = d.id;
LEFT JOIN returns all rows from the left table and matching rows from the right. Unmatched right-side rows show as NULL.
Exercise 2
Question: Find customers who have never placed an order.
SELECT c.name FROM customers c LEFT JOIN orders o ON c.id = o.customer_id WHERE o.id IS NULL;
This pattern (LEFT JOIN + WHERE IS NULL) finds rows in the left table that have no match in the right table.