SQL RIGHT JOIN

  • RIGHT JOIN performs a join starting with the second (right-most) table and then any matching first (left-most) table records.
  • RIGHT JOIN and RIGHT OUTER JOIN are the same.
The definitive guide
for data professionals


Order today!
 See 2 min video



The SQL RIGHT JOIN syntax


The general syntax is:
SELECT column-names
  FROM table-name1 RIGHT JOIN table-name2 
    ON column-name1 = column-name2
 WHERE condition

The general RIGHT OUTER JOIN syntax is:
SELECT column-names
  FROM table-name1 RIGHT OUTER JOIN table-name2 
    ON column-name1 = column-name2
 WHERE condition




SQL RIGHT JOIN Example



Problem: List customers that have not placed orders

SELECT TotalAmount, FirstName, LastName, City, Country
  FROM [Order] O RIGHT JOIN Customer C
    ON O.CustomerId = C.Id
WHERE TotalAmount IS NULL

This returns customers that, when joined, have no matching order.

Results: 2 records

TotalAmount FirstName LastName City Country
NULL Diego Roel Madrid Spain
NULL Marie Bertrand Paris France