Lecture

FULL OUTER JOIN

A FULL OUTER JOIN returns all rows from both the left and right tables.

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

Where no match exists, missing values are filled 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;

This type of join is the union 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

This result includes matched rows, unmatched students, and unmatched classes.


Why It Matters

Use FULL OUTER JOIN when:

  • You need a complete dataset from both tables
  • You're checking for missing relationships
  • You want 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 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