Collecting Data from Databases
Kettle & Crumb's till does not save a spreadsheet. Every sale goes straight into a database, alongside the menu and the loyalty list. When Nisha asks for June's cold-coffee sales, the analyst's first job is to get exactly those rows out, reliably, and in a way that can be repeated next month.
The rule
Ask the database for exactly the rows and columns you need.
A relational database stores data in tables that link to each other through keys:
orders(order_id, order_date, customer_id, item_code, qty, amount)menu(item_code, item, price)customers(customer_id, name, joined)
orders.item_code points to menu.item_code, so item names are stored once in menu rather than copied into every order. You pull data out with SQL, a language for asking questions of tables:
SELECT order_date, item_code, qty, amount
FROM orders
WHERE item_code = 'C01'
AND order_date >= '2025-06-01'
AND order_date < '2025-07-01';SELECTnames the columns you want.FROMnames the table.WHEREkeeps only the rows that pass every condition.
When you need a name from another table, a JOIN matches rows on their shared key, just as VLOOKUP did on a sheet:
SELECT o.order_date, m.item, o.qty
FROM orders AS o
JOIN menu AS m ON m.item_code = o.item_code;Analysts normally get read-only access, often to a copy of the live database, so a mistake cannot damage the till's records.
The shortcut
Before you write the query, fill in three blanks: "I need these columns, from this table, for rows where this is true." They become SELECT, FROM and WHERE, in that order.
Columns
Date, quantity and amount:
SELECT order_date, qty, amount.
The trap is exporting a whole table "to be safe" and filtering by hand. It is slow, it leaves no record of what you kept, and it is easy to get subtly wrong.
Drills
Answer fast — trust the rule.
Which clause keeps only the rows you want?
Why is the item name stored in menu rather than in every order?
Which query returns every order from Asha, whose customer_id is 7?
Why does the query use order_date < '2025-07-01' rather than <= '2025-06-30'?
Remember
- Ask the database for exactly the rows and columns you need.
- Shortcut: columns, table, condition become SELECT, FROM, WHERE.
- Trap: exporting everything and filtering by hand; save the query instead.
