Interactive SQL reference
See exactly which rows a SQL join keeps.
Switch between four join types. Watch unmatched customers and orders enter or leave the result—and notice why one customer can appear more than once.
Join type
customers
| customer_id | customer_name |
|---|---|
| 1 | Ada |
| 2 | Bo |
| 3 | Cy |
orders
| order_id | customer_id |
|---|---|
| 101 | 1 |
| 102 | 1 |
| 103 | 2 |
| 104 | 4 |
SQLMatch on customer_id
SELECT
COALESCE(c.customer_id, o.customer_id) AS customer_id,
c.customer_name,
o.order_id
FROM customers AS c
INNER JOIN orders AS o
ON c.customer_id = o.customer_id
ORDER BY customer_id, order_id;Result3 rows
| customer_id | customer_name | order_id |
|---|---|---|
| 1 | Ada | 101 |
| 1 | Ada | 102 |
| 2 | Bo | 103 |
Matches can multiply rows
Ada has two orders, so the matching customer row appears twice. A join does not preserve the left table’s row count automatically.
NULL marks the missing side
Outer joins retain unmatched records. Columns from the side without a match become NULL.
Dialect support varies
RIGHT and FULL OUTER JOIN syntax is not available in every engine or version. Check your warehouse documentation.
Continue learning
Learn the patterns, then run the query.
The full guide explains join selection, multi-table joins, duplicate rows, and common mistakes. Practice applies those ideas in the browser.
