Intermediate · Lesson 11 of 20

LEFT JOIN - Keep All Left Rows

LEFT JOIN keeps ALL rows from the left table, even if there's no match on the right.

SELECT e.first_name, d.name AS department_name
FROM employees e
LEFT JOIN departments d
ON e.department_id = d.id;

If an employee has no matching department, department_name will be NULL.

INNER JOIN vs LEFT JOIN:

  • INNER JOIN: only matching rows
  • LEFT JOIN: all left rows + matching right rows

LEFT JOIN is essential for finding missing relationships and ensuring no data is lost.

Check your understanding

Get all employees with their department, keeping employees who have no department.

Examples run on the employees sample database. Open any of them in the playground to experiment.