MySQL Outer Join (original) (raw)

Last Updated : 27 Mar, 2026

MySQL provides the JOIN clause to combine rows from two or more tables based on a related column between them. It is useful for retrieving related data from multiple tables efficiently.

Types of Outer Joins in MySQL

MySQL supports the following types of Outer Joins:

LEFT JOIN

The LEFT JOIN, also called LEFT OUTER JOIN, is used to show all rows from the left table along with the matching rows from the right table. If no matches are detected, the right table will return a result of NULL.

Syntax:

SELECT columns FROM table1 LEFT JOIN table2 ON table1.column = table2.column;

Example:

Consider two tables, employees and departments:

employees:

Screenshot-2026-03-27-152534

departments:

Screenshot-2026-03-27-152803

To retrieve all employees along with their department names, using a LEFT JOIN:

SELECT employees.name, departments.department_name FROM employees LEFT JOIN departments ON employees.department_id = departments.department_id;

Result:

Screenshot-2026-03-27-152953

RIGHT JOIN

The RIGHT JOIN, also referred to as RIGHT OUTER JOIN, is used to display all entries from the right table along with any corresponding rows from the left table. If there are no matches, the left table will output NULL.

Syntax:

SELECT columns FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;

Example

Using the same employees and departments tables, to retrieve all departments along with their employees:

SELECT employees.name, departments.department_name FROM employees RIGHT JOIN departments ON employees.department_id = departments.department_id;

Result:

Screenshot-2026-03-27-153422

Practical Applications of Outer Joins

Outer Joins are used to include both matching and non-matching records from tables, ensuring complete data retrieval for analysis