This is the counterpart to a left join—it returns all records from the right table and the matched records from the left table. The result is null from columns of the left table, when there is no match:
The follow query does a right join:
SELECT Reservations.ReservationId, Customers.CustomerName,Reservations.Date
FROM Orders
RIGHT JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
It produces the following result:
ReservationId |
CustomerName |
Date |
123123 |
Alex Hales |
01/02/2018 |
123125 |
Chris Call |
02/02/2018 |
123126 |
Stuart Broad |
03/02/2018 |
Null |
Chris Gayle |
NULL |