RIGHT JOIN

PostgreSQL RIGHT JOIN returns all rows from the right table, with NULLs for unmatched rows from the left table. Learn syntax, examples, and when to use it.

5 min read · Last updated: March 2026 · Back to overview

Quick Answer

PostgreSQL RIGHT JOIN returns every row from the right table and any matching rows from the left table. When no match exists in the left table, the left-side columns appear as NULL. RIGHT JOIN is the mirror of LEFT JOIN — you can always rewrite a RIGHT JOIN as a LEFT JOIN by swapping the table order.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

Introduction to PostgreSQL RIGHT JOIN

The RIGHT JOIN clause joins a right table with a left table and returns every row from the right table, along with matching rows from the left table. When no match exists in the left table, the left-side columns are populated with NULL.

Basic syntax:

SELECT select_list
FROM table1
RIGHT JOIN table2
  ON table1.column_name = table2.column_name;

You can also use the USING shorthand when both tables share the same column name:

SELECT select_list
FROM table1
RIGHT JOIN table2 USING (column_name);

Basic RIGHT JOIN example

Using the DVD rental sample database, the following query retrieves all films and their inventory records — including films with no inventory:

SELECT
  f.film_id,
  f.title,
  i.inventory_id
FROM inventory i
RIGHT JOIN film f ON f.film_id = i.film_id
ORDER BY f.title;

Because film is on the right side, every film row is returned. Films with no inventory entry show NULL in the inventory_id column.

The same query using USING:

SELECT
  f.film_id,
  f.title,
  i.inventory_id
FROM inventory i
RIGHT JOIN film f USING (film_id)
ORDER BY f.title;

RIGHT JOIN with WHERE to find unmatched rows

Add a WHERE filter on a left-table column to isolate rows that have no match — effectively an anti-join:

SELECT
  f.film_id,
  f.title,
  i.inventory_id
FROM inventory i
RIGHT JOIN film f USING (film_id)
WHERE i.inventory_id IS NULL
ORDER BY f.title;

Sample output:

 film_id |         title          | inventory_id
---------+------------------------+--------------
      14 | Alice Fantasia         |         null
      33 | Apollo Teen            |         null
      36 | Argonauts Town         |         null
      38 | Ark Ridgemont          |         null
      41 | Arsenic Independence   |         null

These are films that exist in the catalog but have no physical copies in inventory.

RIGHT JOIN tips

  • Any RIGHT JOIN can be rewritten as a LEFT JOIN by swapping table order. Most teams standardize on LEFT JOIN for consistency.
  • Filter on a non-nullable left-table column with IS NULL in the WHERE clause to find right-table rows with no match.
  • RIGHT OUTER JOIN is identical to RIGHT JOIN — the OUTER keyword is optional.
  • Use table aliases to keep multi-join queries readable, especially when the same table appears more than once.
  • Index the join column on both tables to avoid sequential scans on large datasets.

Continue in Join Tables: SELF-JOIN.

Related in this section: PostgreSQL Joins · Table Aliases · PostgreSQL INNER JOIN

Frequently Asked Questions

What is the difference between RIGHT JOIN and LEFT JOIN in PostgreSQL?

LEFT JOIN preserves all rows from the left (first) table and fills NULLs for unmatched right-table columns. RIGHT JOIN preserves all rows from the right (second) table and fills NULLs for unmatched left-table columns. They are logically equivalent — any RIGHT JOIN can be rewritten as a LEFT JOIN by reversing the table order. Most developers prefer LEFT JOIN for consistency.

When should I use RIGHT JOIN instead of LEFT JOIN?

Use RIGHT JOIN when you want to start your query from the secondary table and need to preserve all its rows. A common case: you have a films table and an inventory table, and you want every film returned even if it has no inventory record. In that scenario, inventory RIGHT JOIN film achieves this. However, swapping to film LEFT JOIN inventory is usually clearer.

Does RIGHT JOIN include rows where both sides match?

Yes. RIGHT JOIN includes all matching rows (like an INNER JOIN) plus the unmatched rows from the right table. Only the rows in the right table that have no match on the left side receive NULLs in the left-table columns.

How do I find rows in the right table with no match in the left table?

Add a WHERE clause that filters for NULL on a non-nullable left-table column. For example: SELECT f.film_id, f.title, i.inventory_id FROM inventory i RIGHT JOIN film f USING (film_id) WHERE i.inventory_id IS NULL ORDER BY f.title; This returns films that have no inventory records.

Is RIGHT OUTER JOIN the same as RIGHT JOIN in PostgreSQL?

Yes. The OUTER keyword is optional — RIGHT JOIN and RIGHT OUTER JOIN are identical in PostgreSQL. The OUTER keyword exists for SQL standard compatibility and readability, but it has no effect on query behavior.