SQL Right Join

SQL Right Join

In SQL, a RIGHT JOIN is used to retrieve all records from the right table and the matching records from the left table based on a specified condition. It returns all the rows from the right table and only the matching rows from the left table. If there is no match, NULL values are returned for the columns of the left table.

The syntax for a RIGHT JOIN is as follows:

sql
SELECT column_list
FROM table1
RIGHT JOIN table2 ON join_condition;

Here, table1 is the left table, table2 is the right table, and join_condition specifies the condition for joining the tables. The column_list represents the columns you want to retrieve from the resulting joined table.

Let’s consider an example to illustrate the usage of a RIGHT JOIN:

Suppose we have two tables, “Customers” and “Orders,” with the following structures and data:

Customers table:

CustomerIDCustomerName
1John
2Emma
3Mike

Orders table:

OrderIDCustomerIDOrderDate
112023-06-01
232023-06-02
322023-06-03
412023-06-04

To retrieve all customers and their corresponding orders (if any), we can use a RIGHT JOIN:

sql
SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate
FROM Customers
RIGHT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;

The result of the above query will be:

CustomerNameOrderIDOrderDate
John12023-06-01
Mike22023-06-02
Emma32023-06-03
John42023-06-04

As you can see, the RIGHT JOIN returns all the rows from the “Orders” table and only the matching rows from the “Customers” table. In this case, all the orders are included, and customers without orders are also included with NULL values in the “CustomerName” column.

Leave a Reply

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

GLOTRU Footer
Popular Features
Popular Services/

Website Development & Design

App Development & Design

Graphic Design

Digital Marketing

SEO (Search Engine Optimization)

SMM (Social Media Marketing)

Cyber Security

Company

GLOTRU Founder & CEO : __Azam

Registared : Trade,MSME,etc

Board of Director

Team

About Us

Contact Us

Privacy Policy

Return & Refund Policy

Abuse Policy

Copyright Policy

Cookie Policy

Terms & Conditions

Universal Terms of Service

Disclaimer

Legal

Sponsorships

Investor

Press Releases

Our Investments

Brands

Newsroom

Business

...

_

Digital Millennium Copyright Act
DMCA.com Protection Status

_

Content similarity detection
Protected by Copyscape

_

***ANTI-PIRACY WARNING***

...................................................................................

Follow Us :

...................................................................................

SECURE SERVER : [Legal] [Privacy Policy] [Universal Terms of Service] [Do not sell my personal information]

SITE HOSTED : GLOTRU SECURE SERVER Asian Data Centre [You can host your site][Click Here]

SSL : Server Type : [Cloudflare] Certificate Issued By : [Let's Encrypt] Signature Algorithm : [ECDSA with SHA-384]

SITE BUILD SOFTWARE : Content Management System (CMS) Softwere

_

_

_