SQL • LESSON 19

RIGHT JOIN

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

🔴 Advanced⏱ 2 Minutes⭐ 320 XP
🤔 THE QUESTION

How can we return only the rows that have a matching record in both tables?

💡 WHAT IS IT?

An INNER JOIN returns only rows where the join condition matches in both tables.

🎯 WHAT IS IT USED FOR?

It is useful when you only want records that have valid related data in both tables.

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

Mission Brief

Practice using RIGHT JOIN to return every department and any matching employee information.

Objectives

  • SELECT
  • FROM
  • RIGHT JOIN
  • ON
  • Table relationships