Skip to content
Learn Netverks

Lesson

Step 19/36 53% through track

joins-outer

OUTER JOINs

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches OUTER JOINs: the SQL patterns, schema habits, and query reasoning you need before advancing in SQL.

JOINs are the heart of relational modeling—Cartesian products and missed ON clauses cause silent wrong counts in analytics.

You will apply OUTER JOINs in contexts like: Reporting dashboards, cohort analysis, and feature tables for ML pipelines.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path. Also draw table relationships on paper before writing ON clauses.

When you can explain the previous lesson's ideas without copying example queries verbatim.

LEFT OUTER JOIN keeps all rows from the left table even when there is no match on the right—essential for “customers with zero orders” reports.

LEFT JOIN

SELECT c.name,
       o.id AS order_id,
       o.total
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;

Practice: Seed customers and orders sample data, then run each query. Verify row counts manually.

Customers without orders appear with NULL order columns.

Finding orphans

SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;

Classic pattern: left join then filter where right-side key IS NULL.

RIGHT and FULL

-- RIGHT JOIN: all rows from right table
SELECT *
FROM orders o
RIGHT JOIN customers c ON c.id = o.customer_id;

-- FULL OUTER: both sides preserved (Postgres; SQLite lacks FULL)

RIGHT JOIN is equivalent to swapped LEFT JOIN. FULL OUTER support varies—check dialect tracks.

Important interview questions and answers

  1. Q: LEFT vs INNER?
    A: LEFT keeps unmatched left rows; INNER drops them.
  2. Q: NULL in outer join?
    A: Missing matches fill with NULL—do not use = NULL; use IS NULL.

Self-check

  1. How do you list customers who never placed an order?
  2. What appears in order columns for customers without orders in LEFT JOIN?

Tip: LEFT JOIN + WHERE right.id IS NULL finds orphans on the left table.

Interview prep

LEFT JOIN keeps?

All left rows; NULLs fill unmatched right columns.

Find customers with no orders?

LEFT JOIN orders, WHERE orders.id IS NULL.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • LEFT vs FULL?
  • NULL in outer join?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump