codescracker


sql

SQL Right Join



« Previous Tutorial Next Tutorial »


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;

Or,

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.

SQL Demo Database

Let's assume we have the following two SQL table named "Admissions" and "Students". This is SQL Table1 (Admissions Table):

sql right join

This is SQL Table2 (Students Table):

sql right outer join

SQL RIGHT JOIN Example

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:

sql right join keyword

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)


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test