Lecture

FULL OUTER JOIN

A FULL OUTER JOIN returns all rows from both the left and right tables, combining them into a single result set.

Where there is a match, the result combines the rows.

Where no match exists, the missing values are represented with NULL.


Syntax

Here is the syntax for a FULL OUTER JOIN:

FULL OUTER JOIN Syntax
SELECT columns FROM table1 FULL OUTER JOIN table2 ON table1.column = table2.column;

Conceptually, this join behaves like a combination of LEFT JOIN and RIGHT JOIN.


Example: Students and Enrollments

Below is an example of a FULL OUTER JOIN between the students and enrollments tables.

students

student_idname
1John Miller
2Lisa Brown
3Michael Johnson
4Emily Davis
5Sarah Thompson

enrollments

student_idclass_name
1Math
1Science
2History
3Art
FULL OUTER JOIN example
SELECT students.name, enrollments.class_name FROM students FULL OUTER JOIN enrollments ON students.student_id = enrollments.student_id;

Result:

nameclass_name
John MillerMath
John MillerScience
Lisa BrownHistory
Emily DavisNULL
NULLArt

The result set includes matched rows as well as unmatched students and classes.


When is FULL OUTER JOIN the right choice?

Use FULL OUTER JOIN when:

  • You need a complete dataset from both tables
  • You're checking for missing relationships
  • You need to audit or reconcile records across tables

Keep in mind: SQLite and MySQL do not support FULL OUTER JOIN directly. You can emulate it using a UNION of a LEFT JOIN and a RIGHT JOIN.

Quiz
0 / 1

What does a FULL OUTER JOIN return in a SQL query?

Only matching rows from both tables.

Rows from the left table only.

All rows from both tables, with NULLs where no match exists.

Rows from the right table only.

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Tables

Execution Result