SQL • LESSON 20

JOIN Multiple Tables

Learn how to combine data from three or more SQL tables using JOINs.

🔴 Advanced⏱ 3 Minutes⭐ 370 XP
🤔 THE QUESTION

How can we return every department, even departments that currently have no employees?

💡 WHAT IS IT?

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

🎯 WHAT IS IT USED FOR?

It is useful when the right-side table is the primary list you want to preserve, even when there is no related record on the other side.

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

Mission Brief

Practice joining employees, departments, and locations to retrieve related information from multiple tables.

Objectives

  • SELECT
  • INNER JOIN
  • Multiple JOINs
  • ON
  • Table relationships