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

Filter by Database
SQL RIGHT JOIN Compatibility Across Databases
Database System Support Status Since Version Notes
MySQL Native all OUTER keyword is optional.
PostgreSQL Native all OUTER keyword is optional.
SQL Server Native all OUTER keyword is optional.
Oracle Native all OUTER keyword is optional. Legacy syntax: WHERE a.id(+) = b.a_id
SQLite Native 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: Native in all listed versions PostgreSQL: Native in all listed versions SQL Server: Native in all listed versions Oracle: Native in all listed versions SQLite: Native since 3.39.0

Per-Database Syntax & Notes

MySQL Native syntax

OUTER keyword is optional.

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

PostgreSQL Native syntax

OUTER keyword is optional.

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

SQL Server Native syntax

OUTER keyword is optional.

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

Oracle Native syntax

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 Native syntax

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;