EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials SQL Tutorial SQL Right Join

SQL Right Join

Roja Metla
Article byRoja Metla
Priya Pedamkar
Reviewed byPriya Pedamkar

Updated June 16, 2023

SQL Right Join

Introduction to SQL RIGHT Join

RIGHT Join gets all the rows from the Right table and the common rows of both tables. In this topic, we will learn about SQL RIGHT Join, So let us take an example of RIGHT Join.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Example: Below represents the Venn diagram of the RIGHT Join.

RIGHT JOIN

In the below diagram, Table A is RIGHT Join to Table B. All the rows from Table B and common rows from both tables are considered here.

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.

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. The 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 are the key differences between 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. The 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. The 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

Loan Table

Borrower 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:

SQL Right Join output 1

The result set contains NULL set values. The 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

Let’s check the output of the above table after applying the RIGHT Join on them.

Output:

SQL Right Join output 2

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:

SQL Right Join output 3

In the above table, LOAN is on the right table, and the borrower is on the left table. We get inner join+ all rows from the right table as in RIGHT join. 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 join will fulfill. As mentioned earlier, joins are used to get data from multiple tables. 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

We hope that this EDUCBA information on “SQL RIGHT Join” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. Composite Key in SQL
  2. Table in MySQL
  3. SQL Keys
  4. AND in SQL
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
All in One Data Science Bundle2000+ Hour of HD Videos | 80 Learning Paths | 400+ Courses | Verifiable Certificate of Completion | Lifetime Access
Financial Analyst Masters Training Program2000+ Hours of HD Videos | 43 Learning Paths | 550+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more