Oracle Tutorial

  • Home
  • Start Here
  • Basics
  • Advanced
    • Oracle View
    • Oracle Index
    • Oracle Synonym
    • Oracle Sequence
    • Oracle Administration
  • PL/SQL
  • Functions
    • Aggregate Functions
    • Analytic Functions
    • Comparison Functions
    • Date Functions
    • String Functions
  • API
    • Python Oracle
Home / Oracle Basics / Oracle FULL OUTER JOIN

Oracle FULL OUTER JOIN

Summary: in this tutorial, you will learn how to use the Oracle FULL OUTER JOIN to query data from multiple tables.

Introduction to Oracle FULL OUTER JOIN clause

Suppose you have two tables T1 and T2. The following illustrates the full outer join of the two tables:

SELECT select_list FROM T1 FULL OUTER JOIN T2 ON join_condition;

For each row in the T1 table, the full outer join compares it with every row in the T2 table.

If rows from both tables meet the join_condition, the full outer join includes columns of both rows in the result set. We say that the row in T1 table matches with the row in the T2 table in this case.

If a row from T1 table does not have any matching row from the T2 table, the full outer join will include columns from the T1 table with null values for all columns from the T2 table.

Similarly, if a row in the T2 table that does not have a matching row in the T1 table, the full outer join will include columns from T2 table with the null values for the columns in the T1 table.

Note that the OUTER keyword is optional, therefore, the FULL OUTER JOIN and FULL JOIN are the same.

This Venn diagram illustrates the full outer join of two tables:

Oracle Joins - Full Outer Join

Oracle FULL OUTER JOIN examples

First, create two tables members and projects. Suppose each member can join zero or one project, and each project can have zero or more members:

CREATE TABLE projects( project_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, project_name VARCHAR2(100) NOT NULL ); CREATE TABLE members( member_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, member_name VARCHAR2(100) NOT NULL, project_id INT, FOREIGN KEY (project_id) REFERENCES projects(project_id) );

Second, insert some projects and members into the projects and members tables:

INSERT INTO projects(project_name) VALUES('ERP'); INSERT INTO projects(project_name) VALUES('Sales CRM'); INSERT INTO members(member_name, project_id) VALUES('John Doe',1); INSERT INTO members(member_name, project_id) VALUES ('Jane Doe',1); INSERT INTO members(member_name, project_id) VALUES ('Jack Daniel',null);

Third, use the full outer join to query data from members and projects tables:

SELECT member_name, project_name FROM members m FULL OUTER JOIN projects p ON p.project_id = m.project_id ORDER BY member_name;

Here is the output:

oracle full outer join example

Jack Daniel does not join any project, Jane Doe and John Doe join the ERP project and Sales CRM project has no member.

To find the project that does not have any member, you use the following query:

SELECT project_name, member_name FROM members m FULL OUTER JOIN projects p ON p.project_id = m.project_id WHERE member_name IS NULL ORDER BY member_name;
oracle full outer join with where clause

Similarly, you can find members who do not participate in any project by using the following query:

SELECT member_name, project_name FROM members m FULL OUTER JOIN projects p ON p.project_id = m.project_id WHERE project_name IS NULL ORDER BY member_name;
oracle full outer join with where clause example 2

In this tutorial, you have learned how to use the Oracle FULL OUTER JOIN clause to query data from multiple tables.

  • Was this tutorial helpful?
  • YesNo
Previous Oracle RIGHT JOIN
Next Oracle CROSS JOIN

Getting Started

  • What Is Oracle Database
  • Install Oracle Database Server
  • Download Oracle Sample Database
  • Create Oracle Sample Database
  • Connect To Oracle Database Server

Oracle Data Manipulation

  • SELECT
  • Oracle DUAL Table
  • ORDER BY
  • SELECT DISTINCT
  • WHERE
  • Table & Column Aliases
  • AND
  • OR
  • FETCH
  • BETWEEN
  • IN
  • LIKE
  • IS NULL
  • Joins
  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN
  • CROSS JOIN
  • Self Join
  • GROUP BY
  • HAVING
  • UNION
  • INTERSECT
  • MINUS
  • GROUPING SETS
  • CUBE
  • ROLLUP
  • PIVOT
  • UNPIVOT
  • INSERT
  • INSERT INTO SELECT
  • INSERT ALL
  • UPDATE
  • DELETE
  • MERGE
  • Subquery
  • Correlated Subquery
  • EXISTS
  • NOT EXISTS
  • ANY
  • ALL

Oracle Data Types

  • Oracle Data Types
  • NUMBER
  • FLOAT
  • BINARY_FLOAT
  • CHAR
  • NCHAR
  • VARCHAR2
  • NVARCHAR2
  • DATE
  • INTERVAL
  • TIMESTAMP
  • TIMESTAMP WITH TIME ZONE

Oracle Data Definition

  • CREATE TABLE
  • Identity Column
  • ALTER TABLE
  • ALTER TABLE ADD Column
  • ALTER TABLE MODIFY Column
  • Drop Columns
  • DROP TABLE
  • TRUNCATE TABLE
  • RENAME Table
  • Oracle Virtual Column

Oracle Constraints

  • PRIMARY KEY
  • FOREIGN KEY
  • UNIQUE
  • CHECK
  • NOT NULL

Oracle Views

  • CREATE VIEW
  • DROP VIEW
  • Updatable Views
  • Inline Views
  • WITH CHECK OPTION

About Oracle Tutorial

OracleTututorial.com website provides Developers and Database Administrators with the updated Oracle tutorials, scripts, and tips.

Search

Recent Tutorials

  • Oracle Implicit Statement Results
  • Calling PL/SQL Stored Functions in Python
  • Calling PL/SQL Procedures in Python
  • Managing Transaction in Python
  • Deleting Data From Oracle Database in Python

Site Links

  • Oracle Books
  • About
  • Contact
  • Privacy Policy
  • Terms of Use

Copyright © 2021 Oracle Tutorial. All Rights Reserved.