MYSQL - RIGHT JOIN Query

RIGHT JOIN Query in mysql is used to join multiple tables which return all the records from the second (right side) table even no matching records found from the first (left-side) table. If it will not find any matches record from the left side  first table, then returns null.

  • We can use MySQL RIGHT JOIN Multiple Tables.
  • We can use RIGHT JOIN with WHERE Clause.
  • We can use MySQL RIGHT JOIN with Group By Clause.
  • We can use MySQL RIGHT JOIN with USING Clause.


MYSQL Syntax :

SELECT field_name1, field_name2, ....
FROM table1
RIGHT JOIN table2
ON Join_Condition;

Mysql right join query

MYSQL Query Example :
SELECT s.stud_id,s.stud_name,m.maths,m.science FROM tblstudent s RIGHT JOIN tblmarks m on s.stud_id=m.stud_id

Right Join mysql query
stud_id stud_name maths science
1 manish patel 45 78
3 Raju modi 65 76
NULL NULL 85 96

Explain: 

  • The tblstudent is the left table and tblmarks is the right table.
  • The RIGHT JOIN returns all rows from the table tblmarks matched records from the table tblstudent.

  • The RIGHT JOIN returns all rows from the right table tblmarks even if there are no matched in the left table (tblstudent) with null value.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

58552