Posted inphp / Mysql / Mysqli

right outer join

Today, We want to share with you right outer join.In this post we will show you right outer join mysql, hear for right outer join vs left outer join we will give you demo and example for implement.In this post, we will learn about SQL OUTER JOIN – Left Join, Right Join and Full Outer Join with an example.

RIGHT OUTER JOIN operation

In this tutorial we learn to all about having Examples like as a Outer Join, union between SQL Left Outer Join and SQL Right Outer Join, find unmatching rows or many more.

Also Read: Eloquent Left Join Queries in Laravel Examples

Syntax for Right Outer Join

SELECT column-name-list FROM 
table-name1 RIGHT OUTER JOIN table-name2 
ON table-name1.column-name = table-name2.column-name;
SELECT * FROM class RIGHT OUTER JOIN class_info ON (class.id = class_info.id);

Execute the following query

SELECT *
FROM Member
     RIGHT OUTER JOIN Branchs ON Member.MemberID = Branchs.MemberID

SELECT *
FROM Branchs
     RIGHT OUTER JOIN Member ON Branchs.MemberID = Member.MemberID

union between SQL Left Outer Join and SQL Right Outer Join

SELECT *
FROM Member
     LEFT OUTER JOIN Branchs ON Member.MemberID = Branchs.MemberID
   UNION ALL
   SELECT *
FROM Member
     RIGHT OUTER JOIN Branchs ON Member.MemberID = Branchs.MemberID

Figure 1. Query

SELECT c.shopper_num, c.fname, c.lname, o.request_num,
o.request_date, o.shopper_num
FROM shopper c RIGHT OUTER JOIN requests o
ON (c.shopper_num = o.shopper_num);

SQL Server RIGHT JOIN example

SELECT
    mobile_name,
    request_id
FROM
    sales.request_items o
    RIGHT JOIN mobileion.mobiles p 
        ON o.mobile_id = p.mobile_id
ORDER BY
    request_id;

MySQL RIGHT JOIN to find unmatching rows

SELECT 
    memberNumber, 
    shopperNumber
FROM
    shoppers
RIGHT JOIN members ON 
	salesRepMemberNumber = memberNumber
WHERE shopperNumber is NULL
ORDER BY memberNumber;

Right Outer Join in SQL Server with Examples

CREATE TABLE Organization
(
    OrganizationId TinyInt Identity Primary Key,
    OrganizationName Nvarchar(50) NULL
)
GO
INSERT Organization VALUES('PAKAINFO')
INSERT Organization VALUES('4CGANDHI')
INSERT Organization VALUES('INFINITYKNOW')
INSERT Organization VALUES('W3SCHOOL')
GO
CREATE TABLE Applicant
(
    ApplicantId tinyint identity primary key,
    FullName nvarchar(50) NULL,
    OrganizationId tinyint REFERENCES Organization(OrganizationId)
)
GO
INSERT Applicant VALUES('Rekha',1)
INSERT Applicant VALUES('Hardik',2)
INSERT Applicant VALUES('Manisha',3)
INSERT Applicant VALUES('Krishna',NULL)
INSERT Applicant VALUES('Mayur',1)
INSERT Applicant VALUES('Ravi',3)
INSERT Applicant VALUES('Bhavna',NULL)
GO

Example

SELECT  App.ApplicantId, 
  App.FullName, 
  App.OrganizationId, 
  Org.OrganizationId, 
  Org.OrganizationName
FROM Applicant App
RIGHT OUTER JOIN Organization Org
ON App.OrganizationId = Org.OrganizationId

I hope you get an idea about right outer join.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype