PREP WITH PROOF
Menu
FREE SQL LEARNING TOOL · NO SIGNUP

SQL JOIN explorer

Why did a join multiply your rows? Trace every matching pair and every unmatched row.

Choose the key values

Each value is a separate row, including repeated keys. Enter up to 20 integers per side, from -1000000 to 1000000, or NULL. Leave either list empty to represent a table with zero rows.

Comma-separated integers or NULL. The join condition is always left.key = right.key. NULL does not match NULL. Submitted values appear in the URL; use invented learning data.

Reset example

Compare the row counts

4 rowsINNER JOIN

6 rowsLEFT JOIN

8 rowsFULL OUTER JOIN

Input: 4 left rows and 4 right rows. Equal known keys produce every left/right pair. Outer joins also preserve rows without a match.

Result: FULL OUTER JOIN

8 output rows · 4 matched pairs · 4 unmatched rows preserved.

L1 and R1 identify the first input rows, not key values. A dash means no source row exists on that side. A NULL key with a row ID is a real input row whose key is missing.

Every output row, with its input provenance
Left rowLeft keyRight rowRight keyReason
L110R110Equal known keys
L110R210Equal known keys
L210R110Equal known keys
L210R210Equal known keys
L320—NULLUnmatched left row
L4NULL—NULLUnmatched left row
—NULLR330Unmatched right row
—NULLR4NULLUnmatched right row

Where the row counts come from

For a known key that occurs m times on the left and n times on the right, matching contributes m × n pairs. If one side has no such key, INNER contributes zero; LEFT preserves only existing left rows; FULL preserves existing rows on either side. The NULL bucket never produces matching pairs under ordinary equality.

Contribution of each key to all three joins
KeyLeft occurrencesRight occurrencesINNER rowsLEFT rowsFULL rows
1022444
2010011
3001001
NULL11012

Run the same case in your database

Select and copy this read-only query. Its CTEs contain only the input rows; it does not create or change stored tables. The query targets PostgreSQL and SQLite 3.39 or later, including FULL OUTER JOIN. Other engines may require different syntax. The ordering keeps provenance easy to compare; SQL results without ORDER BY do not promise this order.

WITH left_input (row_id, key_value) AS (
  VALUES (1, 10), (2, 10), (3, 20), (4, CAST(NULL AS INTEGER))
),
right_input (row_id, key_value) AS (
  VALUES (1, 10), (2, 10), (3, 30), (4, CAST(NULL AS INTEGER))
)
SELECT l.row_id AS left_id, l.key_value AS left_key,
       r.row_id AS right_id, r.key_value AS right_key
FROM left_input AS l
FULL OUTER JOIN right_input AS r
  ON l.key_value = r.key_value
ORDER BY COALESCE(l.row_id, 2147483647), r.row_id;

Diagnose unexpected duplicates

The default example has two occurrences of key 10 on each side. That produces four pairs: L1/R1, L1/R2, L2/R1 and L2/R2. LEFT adds the unmatched left key 20 and left NULL row, giving six rows. FULL also adds right key 30 and right NULL, giving eight. The two NULL rows stay separate because their keys do not establish equality.

When a report grows after a join, write down what one output row is supposed to represent. If you expect one row per order but join two payment rows to three shipment rows for that order, you obtain six combinations. Inspect key frequencies on both sides before changing the query. This tool makes that multiplication visible with small inputs.

Choose a repair that matches the required meaning. Aggregate child rows before joining when you need one summary per parent. Correct an incomplete join condition when the real key includes more columns. Enforce uniqueness when the business relationship truly requires it. Use EXISTS when you need only to test whether a match exists. DISTINCT on a projection can collapse equal displayed values, but it does not decide which child facts should contribute to a total.

Keep the model’s boundary clear

This tool models one scalar integer equality condition with SQL NULL behavior. It is not a database connection, query optimizer or arbitrary SQL runner. It does not model composite keys, text collation, type coercion, filters, aggregation or performance. In particular, a WHERE condition that rejects right-side NULLs after a LEFT JOIN can remove preserved rows; that extra filtering is outside this model.

The input row IDs distinguish repeated source rows. They are not part of the join condition. Generated results were checked against SQLite; validate your final query and business rules on your actual engine and data.

Explore IN, NOT IN and NULL behavior →

Read the SQL exclusion troubleshooting guide →

Official references