PostgreSQL FULL OUTER JOIN (original) (raw)

Last Updated : 12 Jul, 2025

In PostgreSQL, the **FULL OUTER JOIN is a **powerful feature that combines the effects of both **LEFT JOIN and **RIGHT JOIN. This join operation retrieves **all rows from both tables involved in the join, including **unmatched rows from each table. For any unmatched rows, PostgreSQL fills the result with **NULL values for the columns of the table lacking a match.

In this article, we will explain the **syntax and practical use cases of **FULL OUTER JOIN, providing examples with **detailed outputs. By the end, we will have a **complete understanding of how to use FULL OUTER JOIN effectively in our **PostgreSQL database queries to generate understanding and **comprehensive **reports.

PostgreSQL FULL OUTER JOIN

This feature is essential for scenarios where both **matching and **non-matching data are required, such as in **data integration, **comparative analysis, or **comprehensive reporting. FULL OUTER JOIN allows us to bring together data from two sources without losing any information, even if there are gaps in **matching records.

**Syntax

SELECT table1.column1, table1.column2, table2.column1, ....
FROM table1
FULL JOIN table2 ON table1.matching_column = table2.matching_column;

Or alternatively:

SELECT table1.column1, table1.column2, table2.column1, ....
FROM table1
FULL OUTER JOIN table2 ON table1.matching_column = table2.matching_column;

**Key Terms

Venn Diagram for FULL OUTER JOIN

The Venn diagram for FULL OUTER JOIN is given below:

PostgreSQL FULL OUTER JOIN Examples

Let us take a look at some of the examples of FULL OUTER JOIN in PostgreSQL to better understand the concept. In this article, we will be using the **sample DVD rental database, which is explained here and can be downloaded by clicking on this link in our examples.

**Example 1: Films and Actors Query

In this example, we’ll fetch details of **all films along with their **actors. We’ll use the **film table and **actor table to retrieve data, including any records that don’t have a **matching pair in the other table.

**Query:

SELECT
title,
first_name,
last_name
FROM
film f
FULL OUTER JOIN actor a ON a.actor_id = f.film_id;

**Output

PostgreSQL FULL OUTER JOIN Example

**Explanation:

**Example 2: Films and Language Query

Here we will make a query for all the films and the language of the movie using the "**film" table and "**language" table from our sample database.

**Query:

SELECT
title,
name
FROM
film f
FULL OUTER JOIN language l ON l.language_id = f.film_id;

**Output

PostgreSQL FULL OUTER JOIN Example

**Explanation:

Important Points About FULL OUTER JOIN in PostgreSQL

Conclusion

In PostgreSQL, the **FULL OUTER JOIN is an essential tool for cases where we need a complete view of two tables, including both matching and non-matching records. By using FULL OUTER JOIN, we ensure that no data is left out, which is particularly useful in **data integration, **report generation, and **comparative analysis.

However, because **FULL OUTER JOIN can be **resource-intensive, it's crucial to use it selectively and optimize queries for large datasets. By handling **NULLs effectively and **monitoring performance, we can use FULL OUTER JOIN to create insightful and comprehensive reports that bring together diverse data sources in **PostgreSQL.