# One-to-Many Relationship

> A link between two tables. One row on one side goes with many rows on the other.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** One-to-Many, 1:N Relationship, Table Relationship, Parent-Child Table

## Think of it like

It is like a mum and her kids. One mum can have many kids, but each kid has one mum.

## Definition

A one-to-many relationship links two tables. One row in the first goes with many rows in the second. One customer can have many orders, but each order has one customer. You build it with a foreign key. The table on the many side holds a column that points back to the one side, like customer_id on each order.

## Example

Lucy's blog has authors and posts. Each post stores an author_id, so one author can have many posts.

## Example code

```sql
CREATE TABLE orders (
  id INTEGER PRIMARY KEY,
  customer_id INTEGER REFERENCES customers(id),
  total NUMERIC
);
```

Each order points back to one customer. One customer can have many orders.

## Why it matters

It is the most common link between tables. Customers and orders, posts and comments, and teams and players all work this way.

## Common mistake

Putting the link on the wrong side, like a list of order ids in the customer row. The foreign key goes on the many side.

## Three principles

- **One side, many side.** One customer, many orders.
- **Key on the many side.** Each order holds a customer_id.
- **Join to read it.** A join brings both tables together.

## Related terms

- [Foreign Key](https://learn.benibix.com/term/development/foreign-key)
- [Primary Key](https://learn.benibix.com/term/development/primary-key)
- [Entity-Relationship Diagram (ERD)](https://learn.benibix.com/term/data/entity-relationship-diagram)
- [SQL Join](https://learn.benibix.com/term/development/join)
- [Database Normalization](https://learn.benibix.com/term/development/normalization)

![Two boxes joined by a line. The Customer box lists id as the primary key, then name and email. The Order box lists id, customer_id as a foreign key, and total. At the Customer end the line has a single bar, meaning one. At the Order end it splits into a crow's foot, meaning many. A note says one customer can have many orders, and each order has one customer.](https://learn.benibix.com/diagrams/dev-erd.svg)

---

Source: https://learn.benibix.com/term/development/one-to-many-relationship
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-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
