A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

SQL: OUTER JOINs (LEFT, RIGHT, FULL)

College Depth 72 in the knowledge graph ☐ I know this ☆ Set as goal
333prerequisites beneath it
See this on the map →
SQL Joins→
SQL LEFT JOIN RIGHT JOIN FULL OUTER JOIN

Core Idea

LEFT OUTER JOIN includes all rows from the left table and matching rows from the right table (nulls for non-matches). RIGHT OUTER JOIN is the opposite. FULL OUTER JOIN includes all rows from both tables. Outer joins are essential when relationships are optional.

How It's Best Learned

Compare results of INNER vs LEFT JOIN on the same query to understand what rows are included/excluded. Practice scenarios where entities have optional relationships (e.g., employees who may not have assigned projects).

Explainer

You already know that an INNER JOIN combines rows from two tables where a match exists on the join condition — and silently drops any row from either side that has no match. Outer joins solve the problem of those disappearing rows. In real-world data, relationships are often optional: not every customer has placed an order, not every employee has a manager, not every product has been reviewed. An INNER JOIN on customers and orders would simply omit customers who have never ordered, which might be exactly the population you need to analyze.

A LEFT OUTER JOIN (usually written simply as LEFT JOIN) preserves every row from the left table regardless of whether a match exists in the right table. When there is no match, the right table's columns are filled with NULL. Think of it as the left table saying "I'm all showing up — and if I happen to have a partner in the right table, great, bring them along; if not, I'll sit with empty seats." So `SELECT c.name, o.order_date FROM customers c LEFT JOIN orders o ON c.id = o.customer_id` returns every customer: those with orders show their order dates, and those without orders show NULL for order_date. This is the most commonly used outer join in practice.

A RIGHT OUTER JOIN is the mirror image — it preserves all rows from the right table and fills NULLs for unmatched left-side columns. In practice, most developers rewrite RIGHT JOINs as LEFT JOINs by swapping the table order, since reading left-to-right feels more natural. A FULL OUTER JOIN preserves all rows from both tables: rows with matches are combined normally, rows from the left with no right match get NULLs on the right side, and rows from the right with no left match get NULLs on the left side. FULL OUTER JOIN is useful for reconciliation tasks — comparing two datasets to find what exists in one but not the other.

A common pattern with outer joins is using NULL checks to find *non-matching* rows specifically. `SELECT c.name FROM customers c LEFT JOIN orders o ON c.id = o.customer_id WHERE o.id IS NULL` returns only customers who have *never* placed an order — the LEFT JOIN preserves them, and the WHERE clause filters to just the unmatched ones. This "anti-join" pattern is one of the most practical uses of outer joins and appears constantly in data analysis and reporting. Understanding when NULLs appear in your results — and whether they represent missing data or simply non-matching joins — is the key skill that outer joins demand.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Set Operations: Union, Intersection, and Complement → Relational Algebra → SQL: SELECT Statement and Basic Queries → SQL Joins → SQL: OUTER JOINs (LEFT, RIGHT, FULL)

Longest path: 73 steps · 333 total prerequisite topics

Prerequisites (1)

Leads To (0)

No topics depend on this one yet.