Introduction to SQL RIGHT Join
RIGHT Join gets all the rows from the Right table and common rows of both tables. In this topic, we are going to learn about SQL RIGHT Join, So let us take an example of the RIGHT Join.
Example: Below represents the Venn diagram of the RIGHT Join.
In the below diagram Table A is RIGHT Join to table B. Here all the rows from table B get considered and common rows from both tables.
Syntax:
SELECT * FROM TABLE_A A
RIGHT JOIN TABLE_B B
ON A.Common_COLUMN=B.Common_COLUMN
Full Join: Full Join gets all the rows from both tables. Let us take an example of the RIGHT Join.
Example: Below represents the Venn diagram of the FULL join.
Syntax:
SELECT * FROM TABLE_A A
FULL JOIN TABLE_B B
ON A. Common_COLUMN =B. Common_COLUMN
The result set contains NULL set values. Below syntax can be used to neglect the NULL values.
SELECT * FROM TABLE_A A
FULL JOIN TABLE B B
ON A. Common_COLUMN =B. Common_COLUMN
WHERE A.Common_COLUMN IS NULL
AND A.Common_COLUMN IS NULL
Key Differences of LEFT Join vs RIGHT Join
Given below is the key differences of LEFT Join vs RIGHT Join.
LEFT Join | RIGHT Join |
Consider all the rows from the table and common rows from both tables. | Consider all rows from the right table and common from both tables. |
INNER Join + all rows from the left table | INNER Join + all rows from the right table |
Joins based on a condition | Joins based on a condition |
ON keyword is used to specify the condition and join the tables. | ON keyword is used to specify the condition and join the tables. |
The result set contains NULL set values. Below syntax can be used to neglect the NULL values: –
SELECT * FROM TABLE_A A LEFT JOIN TABLE B B ON A. Common_COLUMN =B. Common_COLUMN WHERE B.Common_COLUMN IS NULL |
The result set contains NULL set values. Below syntax can be used to neglect the NULL values: –
SELECT * FROM TABLE_A A RIGHT JOIN TABLE B B ON A. Common_COLUMN =B. Common_COLUMN WHERE A.Common_COLUMN IS NULL |
SELECT * FROM TABLE_A
LEFT JOIN TABLE B ON A. Common_COLUMN =B. Common_COLUMN |
SELECT * FROM TABLE_A
RIGHT JOIN TABLE B ON A. Common_COLUMN =B. Common_COLUMN |
RIGHT Join
- RIGHT Join = All rows from RIGHT table + INNER Join
- Consider all rows from the right table and common from both tables.
- Joins based on a condition
- ON keyword is used to specify the condition and join the tables.
Loan Table
Borrower Table
Examples of SQL RIGHT Join
Here are the following examples of SQL RIGHT Join mention below:
Example#1
Let us consider the above two tables and apply RIGHT Join on the tables: –
Query to get the loan_no, status, and borrower date from two tables: –
Query:
SELECT L.LOAN_NO, L.LOAN_STATUS, B.BORROWER_DATE
FROM LOAN L RIGHT JOIN BORROWER B
ON L.LOAN_NO=B.LOAN_NO
Let’s check the output of the above table after applying the right join on them.
Output:
The result set contains NULL set values. Below syntax can be used to neglect the NULL values: –
SELECT * FROM TABLE_A A
RIGHT JOIN TABLE B B
ON A. Common_COLUMN =B. Common_COLUMN
WHERE A.Common_COLUMN IS NULL
Let us consider two tables and apply RIGHT join on the tables. Query to get the loan_no, status, loan_aount and borrower date from two tables.
Query:
SELECT L.LOAN_NO, L.LOAN_STATUS,L.LOAN_AMOUNT, B.BORROWER_DATE
FROM LOAN L RIGHT JOIN BORROWER B
ON L.LOAN_NO=B.LOAN_NO

4.5 (8,906 ratings)
View Course
Let’s check the output of the above table after applying the RIGHT Join on them.
Output:
Example #2
Let us consider two tables and apply RIGHT join on the tables. Query to get the loan_no, status, loan_aount and borrower date from two tables.
Query:
SELECT L.LOAN_NO, L.LOAN_STATUS,L.LOAN_AMOUNT, B.BORROWER_DATE
FROM BORROWER B RIGHT JOIN LOAN L
ON L.LOAN_NO=B.LOAN_NO
Let’s check the output of the above table after applying the RIGHT Join on them.
Output:
In the above table, LOAN is the right table and the Borrower is the left table. As in RIGHT join, we get inner join+ all rows from the right table. Here we get all the rows from the LOAN table and inner join rows with the Borrower table. Values not present will be NULL.
Conclusion
To fetch data relevant to the customer requirement we might need to join tables that will be fulfilled by joins. As mentioned earlier joins are used to get data from more than one table. To join more than one table we need at least one column common in both tables. Tables get joined based on the condition specified.
Recommended Articles
This is a guide to SQL RIGHT Join. Here we discuss the basic concept, examples of SQL RIGHT Join along with key differences of LEFT Join vs RIGHT Join. You may also have a look at the following articles to learn more –