Right Join in SQL


Right Join in SQL

The SQL RIGHTJOIN 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.

Below are the two tables, STUDENT AND DEPARTMENT

Department table will be as follows

Now if we apply the RIGHT JOIN as follows

					SELECT STUDENT.FirstName, STUDENT.LastName, DEPARTMENT.DepartmentName
ON STUDENT.DepartmentId = DEPARTMENT.DepartmentId

We will get the below result where we will get all the matched rows as well as unmatched rows from the right table and all the matched rows from the left table and NULL value for the unmatched rows.

Please comment and share if you like this post and tell us about how we can enhance our posts in dotnetcoaching. Thanks.