0% found this document useful (0 votes)
52 views3 pages

SQL Right Join

SQL RIGHT JOIN returns all rows from the table mentioned on the right side of the JOIN clause. If there are no matching rows in the left table, NULL values will be returned. It joins two tables, SalesDetails and ClientDetails, on their common ClientID field and returns all rows from ClientDetails along with any matching rows from SalesDetails, returning NULL values for unmatched fields. The query selects the OrderID, ClientName, and OrderDate, ordering the results by descending OrderDate.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

SQL Right Join

SQL RIGHT JOIN returns all rows from the table mentioned on the right side of the JOIN clause. If there are no matching rows in the left table, NULL values will be returned. It joins two tables, SalesDetails and ClientDetails, on their common ClientID field and returns all rows from ClientDetails along with any matching rows from SalesDetails, returning NULL values for unmatched fields. The query selects the OrderID, ClientName, and OrderDate, ordering the results by descending OrderDate.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL RIGHT JOIN

SQL RIGHT JOIN returns all the rows from the right table mentioned with the RIGHT
JOIN clause. If there are no matching rows in left table then output rows will
return NULL values.

Syntax
SELECT columnName(s)
FROM Table1 RIGHT JOIN Table2
ON Table1.columnName = Table2.columnName
Refer below image to understand RIGHT JOIN, here green part is output for RIGHT JOIN.

Here we will consider one example for RIGHT JOIN condition where we will use
two tables named as SalesDetails and ClientDetails.
Table Name: SalesDetails
Table Name: ClientDetails

As you can see, first table has 8 records and second table has 10 records. From above
two tables, we need columns OrderID and OrderDate from SalesDetails table and one
column ClientName from ClientDetails table and sorted in descending order
by OrderDate column. So to get the output from two tables we will use RIGHT JOIN query
as given below.

SELECT SalesDetails.OrderID, ClientDetails.ClientName, SalesDetails.OrderDate


FROM SalesDetails RIGHT JOIN ClientDetails
ON SalesDetails.ClientID = ClientDetails.ClientID
ORDER BY OrderDate DESC

Kindly note the above highlighted records, in RIGHT JOIN all the records are returned
from the table which is mentioned in right side and where there was no matching values it
has returned NULL values.

Also Refer:
 SQL JOINS
 SQL INNER JOIN
 SQL LEFT JOIN
 SQL FULL JOIN
 SQL CROSS JOIN

You might also like