Course contentsShow
← Data Science
Lesson 929 of 2,14524. SQL JoinsFree lesson

RIGHT JOIN Syntax and Semantics

Understanding RIGHT JOIN as the mirror of LEFT JOIN, returning all right-table rows with left-table matches.

RIGHT JOIN Syntax and Semantics

What you'll learn: You'll understand how RIGHT JOIN works as the mirror image of LEFT JOIN, ensuring all rows from the right table appear in your results.

The Core Idea

A RIGHT JOIN returns every row from the right (second) table, along with matching data from the left (first) table where available. If there's no match in the left table, you'll see NULL values for those columns—just like LEFT JOIN, but flipped.

Think of it this way: If LEFT JOIN says "keep everything from the left table," then RIGHT JOIN says "keep everything from the right table."

Basic Syntax

SELECT columns
FROM left_table
RIGHT JOIN right_table
  ON left_table.key = right_table.key

The table listed after FROM is your left table, and the table after RIGHT JOIN is your right table.

The Mirror Relationship

RIGHT JOIN is literally the reverse of LEFT JOIN:

  • A LEFT JOIN B = B RIGHT JOIN A
  • Most developers prefer LEFT JOIN because it reads more naturally from left to right
  • RIGHT JOIN is less common but useful when the "complete" table comes second in your query logic

Practical Example Context

Imagine querying orders RIGHT JOIN customers. This ensures every customer appears in results, even customers with no orders (they'd show NULL for order columns). It's the same as customers LEFT JOIN orders.

Key Takeaway: RIGHT JOIN guarantees all rows from the right table appear in results with NULLs for unmatched left table columns—it's LEFT JOIN's mirror, though LEFT JOIN is typically preferred for readability.