What is RIGHT JOIN (Or RIGHT OUTER JOIN) in MySQL ?

It returns all rows from the right table and the corresponding matching rows from the left table. It is an exact opposite of the LEFT JOIN. Thus the result will contain all the records from the right table, even if the JOIN condition doesn’t find any matching records in the left table.

RIGHT JOIN Syntax

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;

Example of RIGHT JOIN

Customer Table

+------------+--------------+------------+------------+--------+------------+-----------+
| CustomerID | CustomerName | ContactNo  | Address    | CityID | PostalCode | CountryID |
+------------+--------------+------------+------------+--------+------------+-----------+
|          1 | Tarun        | 9999075499 | Madan Puri |    124 |     122001 |        91 |
|          2 | Ram          | 9650423377 | A-487      |     11 |     110085 |        91 |
|          3 | Sham         | 1111111111 | A-485      |     11 |     110085 |        91 |
|          4 | Mohan        | 1234567890 | 454        |    124 |     122002 |        91 |
+------------+--------------+------------+------------+--------+------------+-----------+

Order Table

+---------+------------+---------------------+-----------+
| OrderID | CustomerID | OrderDate           | ShipperID |
+---------+------------+---------------------+-----------+
|       1 |          1 | 2019-10-02 21:23:12 |        11 |
|       2 |          3 | 2019-10-02 21:23:27 |        12 |
|       3 |          5 | 2019-10-02 21:39:21 |        12 |
+---------+------------+---------------------+-----------+

RIGHT JOIN Query

use Shopping;
SELECT C.CustomerName, O.OrderID
FROM Customer C
RIGHT JOIN Orders O
ON C.CustomerID = O.CustomerID
ORDER BY C.CustomerName;

Output

+--------------+---------+
| CustomerName | OrderID |
+--------------+---------+
| NULL         |       3 |
| Sham         |       2 |
| Tarun        |       1 |
+--------------+---------+