Lesson 15 / 37 · Joins

LEFT JOIN keeps every left row and fills the gaps with NULL

Same query, one word changed. Dennis and Margaret are back, with NULL as their department. Notice the count: still 7 employees.

The query

SELECT e.name, d.name AS department
FROM employees e
LEFT JOIN departments d ON d.id = e.dept_id

Try RIGHT JOIN: now every department is kept, Research with a NULL name, and Dennis and Margaret disappear.

Next: A join can multiply rows · All lessons