SQL RIGHT JOIN keyword returns all the rows from the right table (i.e, table2), with the matching rows in the left table (i.e., table1). The result is NULL in the left side when there is no match found.
Here is the general form of the RIGHT JOIN keyword in SQL:
SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name=table2.column_name;
SELECT column_name(s) FROM table1 RIGHT OUTER JOIN table2 ON table1.column_name=table2.column_name;
Note - The RIGHT JOIN is also called RIGHT OUTER JOIN in some databases.
Let's assume we have the following two SQL table named "Admissions" and "Students". This is SQL Table1 (Admissions Table):
This is SQL Table2 (Students Table):
Here is an example of RIGHT JOIN keyword in SQL. The following SQL statement will return all the students:
SELECT admissions.StudentID, Students.Name FROM admissions RIGHT JOIN students ON admissions.studentID=students.studentID ORDER BY admissions.studentID;
After querying the above SQL Statements, you will get the following output:
Note - The RIGHT JOIN keyword returns all the rows from the right table (i.e., Students), even if there are no matches found in the left table (i.e., Admissions)
© Copyright 2021. All Rights Reserved.