...

Database Managment - MySql

Back to Course

Lesson Description


Lession - #1336 SQL Right Join



RIGHT JOIN: 

Consider the two tables below:
Student
Sorry cannot be displayed

StudentCourse
Sorry cannot be displayed


The RIGHT JOIN function is analogous to the LEFT JOIN function. This join retrieves all rows from the table on the right side of the join, as well as matching rows from the table on the left. The result-set will include null for the rows for which there is no matching row on the left side. RIGHT OUTER JOIN is another name for RIGHT JOIN.mysql connector java

Syntax:

SELECT table1.column1,table1.column2,table2.column1,....
FROM table1 
RIGHT JOIN table2
ON table1.matching_column = table2.matching_column;


table1: First table.
table2: Second table
matching_column: Column common to both the tables.


Note that instead of using RIGHT JOIN, we can use RIGHT OUTER JOIN.

Sorry cannot be displayed
Example Queries(RIGHT JOIN>
:


The names and ages of students registered in various classes will be displayed using this query.

SELECT Student.NAME,StudentCourse.COURSE_ID 
FROM Student
RIGHT JOIN StudentCourse 
ON StudentCourse.ROLL_NO = Student.ROLL_NO;


Output:

Sorry cannot be displayed