Learn SQL Lesson
LEFT JOIN Keeps the Left Side
A `LEFT JOIN` keeps every row from the left table and fills missing right-side values with `NULL`.
SELECT d.name AS department_name, e.name AS employee_name
FROM departments AS d
LEFT JOIN employees AS e
ON d.id = e.department_id
This is useful when you want to keep all rows from one table, even if some of them do not have a match in the other table.
In this example, Support still appears even though nobody works there.
Practice challenge
Show every department and any employee assigned to it. Return department_name and employee_name, ordered by department_name and then employee_name. Make sure Support still appears even though nobody works there.