In a tidy kitchen, one jar holds one spice. If pepper, salt and sugar are mixed in one jar labelled "pepper, salt, sugar", you can't take just the salt. Replacing the sugar also means digging through the jar. A table is the same: one cell (the box where one row meets one column) is one jar, and the value inside it is the spice. The mixed jar is a cell holding a list, like an items column holding 'Milk Coffee, Toast'.
The first rule of normalisation forbids cells that hold a list. Normalisation is tidying tables step by step (1NF, 2NF, 3NF), so no data is stored twice and no data contradicts itself. The first step is First Normal Form (1NF): every cell in a table holds one value only, not a list.
The 1NF rules
A table is in 1NF when:
- Every column holds one value in each row. A value that isn't split any further is called atomic.
- There is no list in a cell: no comma-separated text, no JSON array like
["a","b"], no object like{"key":"val"}. - There are no repeating columns like
phone1,phone2,phone3for the same kind of data. - Every row can be told apart by a primary key.
A table that breaks 1NF
Imagine Sunset Coffee doesn't have order_items yet (the table of order contents from the Cardinality & Relationships lesson). Someone writes each order's contents straight into the orders table:
| id | customer | items |
|---|---|---|
| 1 | Budi | Milk Coffee, Toast |
| 2 | Budi | Palm Sugar Milk Coffee |
| 3 | Siti | Milk Tea, Milk Coffee |
It looks neat and saves a table. The trouble starts as soon as you run a query on it.
Why a list in one cell breaks queries
The question is simple: which orders contain Milk Coffee? The right answer: #1 and #3. These two queries try to answer it, and the result of each one is written on the -- line below it:
SELECT id FROM orders WHERE items = 'Milk Coffee';
-- 0 rows
SELECT id FROM orders WHERE items LIKE '%Milk Coffee%';
-- 1, 2, 3
=matches the whole cell. No cell is exactly'Milk Coffee', so the result is empty.LIKE '%Milk Coffee%'looks for a piece of text anywhere (%means "any text").'Palm Sugar Milk Coffee'contains that piece too, so order #2 gets picked up, though it holds no Milk Coffee.
Changing data becomes dangerous too. Sunset Coffee wants to rename Milk Coffee to Classic Milk Coffee. REPLACE replaces every piece of text 'Milk Coffee' in the items cell:
UPDATE orders SET items = REPLACE(items, 'Milk Coffee', 'Classic Milk Coffee');
Order #2 turns into 'Palm Sugar Classic Milk Coffee', a product name that never existed. A question like "how many orders per product?" also can't be answered with GROUP BY (the SQL command that groups rows with the same value), because every cell holds a different mix.
The fix: one row per value
The list moves to its own table, order_items, with one row for one product in one order:
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer TEXT NOT NULL
);
CREATE TABLE order_items (
order_id INTEGER NOT NULL REFERENCES orders(id),
product TEXT NOT NULL,
PRIMARY KEY (order_id, product)
);
What order_items holds after the split:
| order_id | product |
|---|---|
| 1 | Milk Coffee |
| 1 | Toast |
| 2 | Palm Sugar Milk Coffee |
| 3 | Milk Tea |
| 3 | Milk Coffee |
SELECT order_id FROM order_items WHERE product = 'Milk Coffee';answers 1 and 3, exactly. NoLIKEneeded.UPDATE order_items SET product = 'Classic Milk Coffee' WHERE product = 'Milk Coffee';changes 2 rows, and Palm Sugar Milk Coffee isn't touched.PRIMARY KEY (order_id, product)makes every row unique. This is the linking tableorder_itemsfrom the Cardinality & Relationships lesson, but itsproductcolumn still holds the product's name as text. The Second Normal Form lesson replaces it with aproduct_idpointing at theproductstable.
Phone numbers: the most common case
A phones column in the customers table holding '07700 900111, 07700 900333' breaks 1NF the same way. So does a hobbies column holding 'reading, coding, gaming'. The fix is the same as well: a separate table with a foreign key to the owner. For phone numbers, the table is phone_numbers:
CREATE TABLE phone_numbers (
id INTEGER PRIMARY KEY,
customer_id INTEGER NOT NULL REFERENCES customers(id),
number TEXT NOT NULL
);
In this table, Budi has two rows and Siti one row: one row per number. There are three other "fixes" people often try, and here is why none of them helps:
phone2andphone3columns. A fourth number has nowhere to go, most cells stay empty, and finding one number means checking three columns.- A JSON array in the same column. It is still a list in one cell.
- Comma-separated, then split in the app. The database still can't search, count or guard the numbers.
📌 A comma doesn't always mean a list
There is a quick way to check 1NF, and it is the one the exercise uses: a cell containing a comma, [ or { may hold a list. But the real question is "does your app need to search, count or change its parts one by one?". The address '5 Jasmine Street, Bristol' contains a comma. But if the address is always used whole, it is one value. If you need to find customers by city, split the city into its own column.
⚠️ Patches that still break 1NF
phone1,phone2,phone3. Repeating columns still break 1NF. The list only moves, spreading sideways into several columns.LIKE '%...%'as a patch.LIKEfinds pieces of text, not values, so Palm Sugar Milk Coffee counts as Milk Coffee.- Thinking JSON makes it tidy.
["07700 900111","07700 900333"]is still one cell holding two values. - A wrong answer string in the exercise. Return
"breaks 1NF"or"meets 1NF"exactly, withNFin capitals.
TL;DR: 1NF (First Normal Form) is the first rule of normalisation, the way of tidying tables so no data is stored twice. 1NF means every cell holds one value (atomic): no comma-separated text, arrays, objects, or repeating columns like phone1, phone2. A list in one cell breaks queries. Say an items column holds 'Milk Coffee, Toast', and you search for the orders with Milk Coffee. Then matching the whole cell with = finds nothing, LIKE (a search for a piece of text) also picks up the Palm Sugar Milk Coffee order, and REPLACE (text replacement) invents fake product names. The fix: move the list into its own table, one row per value, with a foreign key to its owner (order_items for an order's contents, phone_numbers for phone numbers).
⚡ One cell, one value
Meaning: 1NF (First Normal Form) is the first rule of normalisation (a way of tidying tables). 1NF means every cell holds one value only (atomic). No comma-separated text, arrays, objects, or repeating columns (columns of the same kind with a number) like phone1, phone2.
In the exercise, return "breaks 1NF" or "meets 1NF" exactly, with NF in capitals.
⚡ A list in one cell breaks queries
Write:
SELECT id FROM orders WHERE items LIKE '%Milk Coffee%';
-- 1, 2, 3
Guess first: in the orders table, the items column holds each order's list of products, such as 'Milk Coffee, Toast'. Order #2 only holds Palm Sugar Milk Coffee. Why is order #2 found too?
LIKE with % looks for a piece of text anywhere, not a whole value. 'Palm Sugar Milk Coffee' contains the piece Milk Coffee too.
Meaning: When one cell holds a list, = (which matches the whole cell) finds nothing, and LIKE also picks up the wrong rows.
⚡ One row per value
Write:
CREATE TABLE order_items (
order_id INTEGER NOT NULL REFERENCES orders(id),
product TEXT NOT NULL,
PRIMARY KEY (order_id, product)
);
Meaning: The list moves to its own table, order_items: one row per product in one order, with a foreign key order_id to its order. Now WHERE product = 'Milk Coffee' answers orders 1 and 3, exactly.