</>
Skip to content
SQL lessons (27/54)

SQL — Right Join

Basic RIGHT JOIN

SELECT u.name, o.total
FROM users u
RIGHT JOIN orders o ON u.id = o.user_id;

All orders with users

-- Orders without users will have NULL
SELECT u.name, o.total
FROM users u
RIGHT JOIN orders o ON u.id = o.user_id;

Convert RIGHT to LEFT

-- RIGHT JOIN
SELECT u.name, o.total
FROM users u
RIGHT JOIN orders o ON u.id = o.user_id;

-- Equivalent LEFT JOIN
SELECT u.name, o.total
FROM orders o
LEFT JOIN users u ON o.user_id = u.id;

Find orders without users

SELECT o.*
FROM users u
RIGHT JOIN orders o ON u.id = o.user_id
WHERE u.id IS NULL;

Mini Practice

  1. Perform RIGHT JOIN
  2. Convert RIGHT to LEFT JOIN
  3. Find orphaned records
  4. Use with WHERE clause

Up Next

Continue with Subqueries - Sub-queries.

Related Topics

Frequently Asked Questions about Right Join

What is Right Join in SQL?

Right Join is a fundamental concept in SQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Right Join?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Right Join.

Why is Right Join important in SQL?

Right Join is essential for SQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.