SQL RIGHT JOIN Keyword
It will take approximately 3 minutes to read this article.
The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches in the left table. This means that if the ON clause matches 0 (zero) records in the left table; the join will still return a row in the result, but with NULL in each column from the left table.
This means that a right join returns all the values from the right table, plus matched values from the left table or NULL in case of no matching join predicate.
Consider the following two tables,
Table 1 − Orders Table is as follows.
Table 2 − Employees Table is as follows.
Now, let us join these two tables using the LEFT JOIN as follows.
SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
This would produce the following result −
We can also use RIGHT OUTER JOIN instead of RIGHT JOIN, both are same.
You can look here to read about it more.