MySQL

adplus-dvertising
Right Join in MySQL
Previous Home Next

It allow us to get all the output depends on the right side of the defined table whose condition either matches the row on the other table or not

Syntax for right join

SELECT columnname1, columnname2
FROM tablename1
RIGHT JOIN tablename2 
[WHERE CLAUSE
ORDER BY CLAUSE]

Example

SELECT *
FROM studadr 
RIGHT JOIN studinfo 
ON studinfo.sid = studadr.sid ;

It will display only 11 row because rightmost table "studinfo" contains only that much related common rows from the studadr table.

Example

SELECT *
FROM studinfo 
RIGHT JOIN studadr 
ON studinfo.sid = studadr.sid ;

Display all the output related to studadr along with studinfo which includes 15 row and studinfo contain 11 row rest of the entity is null shown in image.

Example

SELECT studadr.said, studinfo.sid, studinfo.fname,
       studinfo.age, studadr.street, studadr.state
FROM studadr 
RIGHT JOIN studinfo 
ON studinfo.sid = studadr.sid ;

Display the selected result because of change in right table define in the code

Example

SELECT studadr.said, studinfo.sid, studinfo.fname,
       studinfo.age, studadr.street, studadr.state
FROM studinfo 
RIGHT JOIN studadr 
ON studinfo.sid = studadr.sid ;

Get the output on the basis of right table specified in the code

Example

SELECT a.said,i.sid,i.fname,i.age,a.street,a.state
FROM studadr a 
LEFT JOIN studinfo i
ON i.sid = a.sid 
WHERE i.sid is null ;

In the above code we get the output NULL is present

Previous Home Next