SQL RIGHT JOIN
Published Jul 13, 2022
Contribute to Docs
The RIGHT JOIN command combines matching rows with rows from the right-side table.
Syntax
SELECT column_name(s)
FROM table_1
RIGHT JOIN table_2
ON table_1.column_name = table_2.column_name;
Every row in the right table is returned in the result set, and if the join condition is not met, then NULL values are used to fill in the columns from the left table.
Example
To create a result set of every row in the students table combined with the transfer_data table where student IDs match. If the ON condition is not met, then NULL values are used to fill in the columns from the transfer_data table.
SELECTstudents.first_name,students.last_name,students.overall_gpa,transfer_data.overal_gpaFROM studentsRIGHT JOIN transfer_dataON students.student_id = transfer_data.student_id;
The result set will only include last name, first name, and both GPAs.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Learn to analyze data with SQL and prepare for technical interviews.
- Includes 9 Courses
- With Certificate
- Beginner Friendly.17 hours
- Learn how to query SQL databases and design relational databases to efficiently store large quantities of data.
- Includes 5 Courses
- With Certificate
- Beginner Friendly.13 hours