SQL JOIN: combine two tables (like VLOOKUP)
Business data is split across tables: orders in one, products in another, customers in a third. A JOIN puts them side by side by matching a shared ID, the way VLOOKUP pulls a value from another sheet. The difference is that a join brings back every column you ask for in one go.
The ON part is the matching rule. Below, each order's customer_id is matched to the id in customers, so every order row gains that customer's name and country.

Syntax
SELECT a.col, b.col
FROM table_a a
JOIN table_b b ON b.id = a.b_id;
Try itEdit the query, then Run
| order_id | order_date | name | country |
|---|---|---|---|
| 1 | 2026-01-01 | Umar Shah | Canada |
| 2 | 2026-01-01 | Leo Brown | United States |
| 3 | 2026-01-01 | Quinn Shah | India |
| 4 | 2026-01-02 | Umar Tanaka | Nigeria |
| 5 | 2026-01-02 | Chen Novak | Germany |
| 6 | 2026-01-02 | Chen Okafor | Canada |
| 7 | 2026-01-03 | Aisha Brown | United States |
| 8 | 2026-01-04 | Ximena Müller | United States |
| 9 | 2026-01-04 | Dana Haddad | United States |
| 10 | 2026-01-04 | Pedro Brown | United States |
10 rows
The four kinds of join
- JOIN (also written INNER JOIN): only rows that match on both sides. Unmatched rows disappear.
- LEFT JOIN: every row from the first table, with empty values where nothing matched. This is VLOOKUP keeping the #N/A rows.
- RIGHT JOIN: the mirror image. Most people just swap the tables and use LEFT JOIN.
- FULL OUTER JOIN: everything from both sides, matched where possible.
Joining more than two tables is just more JOIN lines, one per table.
Your turn
Show each order's id, the product name and the quantity, by joining orders to products.
JOIN products p ON p.id = o.product_id.
This page on one card
