Skip to content

SQL RIGHT JOIN Keyword

RIGHT JOIN is the mirror image of LEFT JOIN. It keeps every row of the second table, the one on the right, and fills the first table’s columns with NULL where nothing matches.

SELECT columns
FROM table1
RIGHT JOIN table2 ON table1.column = table2.column;

RIGHT OUTER JOIN is another name for the same thing.

RIGHT JOIN: every row of table2, with the matching rows of table1

The examples use the Productions and Invoices tables from the example database.

With Productions on the right, every production is kept, whether or not it has invoices:

SELECT Invoices.InvoiceID, Productions.Title
FROM Invoices
RIGHT JOIN Productions ON Invoices.ProductionID = Productions.ProductionID
ORDER BY Productions.Title;
InvoiceID Title
Fennick’s Return
1002 Quarry Lane
Saltmarsh
1004 Six Bells
1001 The Lantern Keepers
1003 The Lantern Keepers

These are the same rows that Productions LEFT JOIN Invoices returns. Any right join can be written as a left join by swapping the two tables, and most people do exactly that, because a query that always keeps “the table I started from” is easier to follow.