Skip to main content
Practice

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.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.