Returns all rows from the right table and matching rows from the left; NULLs fill unmatched left-side columns.

Returns all rows from the right table and matched rows from the left; non-matching left rows produce NULLs. Less commonly used than LEFT JOIN since you can usually reverse the table order. Best reserved for queries where the right table defines the canonical set.

Compatibility

Show:
Database System Support Status Since Version Notes
MySQL ✓ Supported all OUTER keyword is optional.
PostgreSQL ✓ Supported all OUTER keyword is optional.
SQL Server ✓ Supported all OUTER keyword is optional.
Oracle ✓ Supported all OUTER keyword is optional. Legacy syntax: WHERE a.id(+) = b.a_id
SQLite ✓ Supported 3.39.0 RIGHT JOIN added in SQLite 3.39.0 (July 2022). Rewrite as LEFT JOIN with tables swapped for older versions.

Details

RIGHT JOIN is the mirror of LEFT JOIN. Since it can always be rewritten as a LEFT JOIN with tables swapped, it is less commonly used.

Standard Syntax

SELECT a.col, b.col FROM table_a a RIGHT JOIN table_b b ON a.id = b.a_id;

Version Support

MySQL: Since all PostgreSQL: Since all SQL Server: Since all Oracle: Since all SQLite: Since 3.39.0

Per-Database Syntax & Notes

MySQL

OUTER keyword is optional.

SELECT a.col, b.col FROM a RIGHT JOIN b ON a.id = b.a_id;

PostgreSQL

OUTER keyword is optional.

SELECT a.col, b.col FROM a RIGHT JOIN b ON a.id = b.a_id;

SQL Server

OUTER keyword is optional.

SELECT a.col, b.col FROM a RIGHT JOIN b ON a.id = b.a_id;

Oracle

OUTER keyword is optional. Legacy syntax: WHERE a.id(+) = b.a_id

SELECT a.col, b.col FROM a RIGHT JOIN b ON a.id = b.a_id;

SQLite

RIGHT JOIN added in SQLite 3.39.0 (July 2022). Rewrite as LEFT JOIN with tables swapped for older versions.

SELECT a.col, b.col FROM a RIGHT JOIN b ON a.id = b.a_id;