RIGHT JOIN keyword allows you to return all records from the right table, and only those records from the left table that match the record.
SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
RIGHT JOIN Employees
ON Orders.EmployeeID = Employees.EmployeeID
Example
| OrderID | CustomerID | EmployeeID | OrderDate | ShipperID |
|---|
| 10308 | 2 | 1 | 1996-09-18 | 3 |
| 10309 | 37 | 8 | 1996-09-19 | 1 |
| 10310 | 77 | 1 | 1996-09-20 | 2 |
| And a selection from the “Employees” table: | | | | |
| EmployeeID | LastName | FirstName | BirthDate | Photo |
|---|
| 1 | Davolio | Nancy | 12/8/1968 | EmpID1.pic |
| 2 | Fuller | Andrew | 2/19/1952 | EmpID2.pic |
| 3 | Leverling | Janet | 8/30/1963 | EmpID3.pic |
| Result | | | | |
| OrderId | LastName | FirstName |
|---|
| 10308 | Davilio | Nancy |
| NULL | Fuller | Andreq |
| 10310 | Davilio | Nancy |
| NULL | Leverling | Janet |