Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

RIGHT JOIN

RIGHT JOIN

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:

Example

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).