The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.
PS! In some databases RIGHT JOIN is called RIGHT OUTER JOIN.
In this tutorial we will use the well-known Northwind sample database.
Below is a selection from the "Orders" table:
And a selection from the "Employees" table:
|1||Davolio||Nancy||12/8/1968||EmpID1.pic||Education includes a BA in psychology.....|
|2||Fuller||Andrew||2/19/1952||EmpID2.pic||Andrew received his BTS commercial and....|
|3||Leverling||Janet||8/30/1963||EmpID3.pic||Janet has a BS degree in chemistry....|
The following SQL statement will return all employees, and any orders they have placed:
Note: The RIGHT JOIN keyword returns all the rows from the right table (Employees), even if there are no matches in the left table (Orders).