SQL • LESSON 18

LEFT JOIN

Learn how to keep all rows from the left table while matching related data.

🟡 Intermediate⏱ 2 Minutes⭐ 310 XP
🤔 THE QUESTION

How can we keep every employee even when there is no matching department?

💡 WHAT IS IT?

A LEFT JOIN keeps all rows from the left table and adds matching rows from the right table when they exist.

🎯 WHAT IS IT USED FOR?

It is useful when you need a complete list from one table while optionally adding related information from another table.

💻 EXAMPLE
SELECT
e.name,
d.department_name
FROM employees e
LEFT JOIN departments d
  ON e.department_id = d.department_id;

Mission Brief

Practice using LEFT JOIN to return every employee and their matching department information.

Objectives

  • SELECT
  • FROM
  • LEFT JOIN
  • ON
  • Table relationships