SQL Tutorial 0/85 lessons ~6 min read Lesson 21
One-to-Many Relationship
1:N is the most common relationship — one parent row has many children.
Course progress0%
Focus
6 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
1:N is the most common relationship — one parent row has many children. One user has many orders, one author has many books, one team has many members.
Understanding the topic
Core concepts to understand:
- FK on the child side:
orders.user_id REFERENCES users(id). - No UNIQUE on the FK — many children allowed.
- Always index the child's FK column.
- Listing children:
WHERE user_id = ?. - Deleting parent: choose CASCADE / RESTRICT.
Syntax reference
Visual workflow / architecture:
bash
users orders┌────┐ 1:N FK ┌──────────┐│ id │ ◀───────── │ user_id │└────┘ │ total ││ created │└──────────┘ many rows per user
Real-world use
Every customer-orders, post-comments, channel-messages and account-transactions schema is 1:N.
Best practices
- Index the FK column always.
- Pick a delete strategy explicitly.
- Don't denormalize counts unless you measure a need.
Hands-on exercise
Interview preparation — practice these questions:
- Q1. Where does the FK live in 1:N?
- Q2. Why index that column?
- Q3. Two patterns to count children quickly.
- Q4. CASCADE vs RESTRICT trade-offs.
- Q5. Examples of 1:N from your last project.
Ready to mark this lesson complete?Track your journey across the entire course.