Start here
An interviewer says: "Design the warehouse for an online shop." The first thing they check is one sentence. What does one row of your main table mean?
That meaning is called the grain. You met it in the SQL chapters: in orders, one row is one order. In order_items, one row is one product in one order.
Here are the shop tables again. Both describe the same sales, but at two different grains.
| order_id | customer_id | status | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | paid | 40.00 | 2026-01-03 |
| 102 | 1 | paid | 25.00 | 2026-01-10 |
| 103 | 2 | refunded | 60.00 | 2026-01-11 |
| 104 | 3 | paid | 15.50 | 2026-01-15 |
| 105 | 3 | pending | NULL | 2026-01-20 |
| 106 | 4 | paid | 80.00 | 2026-01-21 |
| order_id | product_id | quantity |
|---|---|---|
| 101 | 1 | 2 |
| 101 | 2 | 1 |
| 102 | 3 | 1 |
| 103 | 4 | 1 |
| 104 | 1 | 3 |
| 106 | 5 | 1 |
| 106 | 4 | 1 |
This chapter goes deeper. You learn five things.
- How to write the grain as one sentence, and what it gives you.
- The three kinds of fact table, each shown with shop rows.
- How a wrong grain gives wrong counts and wrong totals.
- Which numbers you can add up, and which you cannot.
- How to choose the grain.
