The RIGHT JOIN command retrieves all rows from the right table and the matching records from the left table. If there is no match, NULL values are returned from the left side.
The following SQL will return all employees along with any orders they might have placed:
SELECT Orders.OrderID, Employees.LastName, Employees.FirstName FROM Orders RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID ORDER BY Orders.OrderID; |
Note: The RIGHT JOIN keyword retrieves all records from the right table (Employees), irrespective of whether there are matches in the left table (Orders).