SQL Joins Table

–five join types - the interview question that filters out half of candidates
Join typeReturnsWhen the other side has no match
INNER JOINOnly matching rows from both tablesRow is excluded entirely
LEFT JOINAll rows from the left table, matched rows from the rightRight columns are NULL
RIGHT JOINAll rows from the right table, matched rows from the leftLeft columns are NULL
FULL OUTER JOINAll rows from both tablesMissing side is NULL
CROSS JOINEvery row × every row (Cartesian product)No join condition - every combination
The five join types follow the PostgreSQL tutorial on joins, which implements the SQL standard more faithfully than most databases. The join you use most is LEFT JOIN (also written LEFT OUTER JOIN - the OUTER is optional), which is how you find rows that do NOT have a match: WHERE right_table.id IS NULL. Bottom line: INNER JOIN is the intersection, FULL OUTER JOIN is the union, LEFT JOIN keeps the left side whole and fills gaps with NULL - and CROSS JOIN with no WHERE clause produces the Cartesian product that brings down production databases. Query context: HTTP status codes table, GCD and LCM calculator for set intersection intuition, JSON to CSV.

SQL joins combine rows from two tables based on a condition - and the five join types determine what happens when there is no match. INNER JOIN keeps only matches, LEFT JOIN preserves the entire left table, RIGHT JOIN preserves the right, FULL OUTER JOIN keeps everything, and CROSS JOIN produces every combination.

The interview question is always LEFT JOIN with IS NULL - which finds rows in one table that have no match in the other. The production question is why your CROSS JOIN is returning 10 million rows.

How to use

  1. Filter by join type or keyword - inner, outer, cross - to see the one you need.
  2. Read the third column: what happens to rows that have no match determines the join type.
  3. Use LEFT JOIN + IS NULL to find unmatched rows - the most common real-world join pattern.

Frequently asked questions

What is the difference between LEFT JOIN and LEFT OUTER JOIN?

Nothing - OUTER is optional in the syntax. LEFT JOIN and LEFT OUTER JOIN are identical. The OUTER keyword exists for readability and symmetry with FULL OUTER JOIN, but every database engine treats them the same. Most style guides drop the OUTER for brevity.

Can I JOIN more than two tables?

Yes - joins chain left to right. A JOIN B JOIN C first joins A and B, then joins the result with C. Each join produces an intermediate virtual table that the next join operates on. The order matters for LEFT/RIGHT joins because it determines which table’s rows are preserved at each step.

What is the difference between ON and WHERE in a LEFT JOIN?

Conditions in ON filter which rows match during the join, but NULL rows from the left table are still preserved. Conditions in WHERE filter the final result after the join - so putting a right-table condition in WHERE turns a LEFT JOIN into an INNER JOIN by eliminating the NULL rows. This is the most common SQL logic bug.

When would I use a CROSS JOIN?

CROSS JOIN produces every combination - useful for generating all possible pairs (products × regions for a sales matrix), creating date spines (every date × every store), or building test data. With a WHERE clause it behaves like an INNER JOIN with a complex condition.

Related tools