# SQL Join

> The part of a query that pairs rows from two tables. You get one result.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** JOIN, Table Join

## Think of it like

Think of it like matching socks from two piles. You pair each sock with the one that fits it.

## Definition

A join is the part of an SQL query that puts rows from two tables side by side. It matches them on a shared value, most often a foreign key and the primary key it points to. The result looks like one table, built just for that question. Inner joins keep only matches, and left joins keep every row from the first table. Joins are how a relational database answers questions that span tables.

## Example

Emma wants each order with the buyer's name. Orders hold only a customer id, so she joins them to customers.

## Example code

```sql
SELECT customers.name, orders.total
FROM customers
JOIN orders ON orders.customer_id = customers.id;
-- Emma | 25.0
-- Emma | 40.0
-- Jack | 15.5
```

Each order comes back with the name of the person who placed it.

## Why it matters

Data is split across tables to keep it clean. Joins put it back together when you need it.

## Common mistake

Leaving out the ON part. Then each row is paired with every other row, and the result is huge.

## Three principles

- **Two tables, one answer.** Rows are matched side by side.
- **Match on keys.** Most often a foreign key and a primary key.
- **Kinds of join.** Inner keeps matches, left keeps all.

## Related terms

- [Inner Join](https://learn.benibix.com/term/development/inner-join)
- [Left Join](https://learn.benibix.com/term/development/left-join)
- [Foreign Key](https://learn.benibix.com/term/development/foreign-key)
- [Database Query](https://learn.benibix.com/term/development/query)

---

Source: https://learn.benibix.com/term/development/join
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
