MySQL Sample Database
Almost every example in this course uses the same small database, called shop. It models an online grocery store: customers place orders, each order contains several products, products belong to categories and come from suppliers, and employees handle the orders. Every playground starts from a fresh copy, so feel free to change data.
The tables
| Table | Rows | What it holds |
|---|---|---|
categories |
6 | product groups such as Beverages and Dairy (description is NULL for Household) |
suppliers |
6 | the companies we buy from, with contact name, city, country and phone |
products |
20 | name, category, supplier, unit_price, units_in_stock and a discontinued flag |
customers |
15 | name, email (NULL for three customers), city, country and signup_date |
employees |
8 | staff with title, hire_date, salary and manager_id pointing at another employee |
orders |
22 | who ordered, which employee handled it, order_date, shipped_date and status |
order_details |
51 | the lines of each order: product, quantity, unit_price and discount |
The diagram below shows how the tables are linked. Each arrow is a foreign key: the column on the left holds a primary key value of the table on the right.
order_details.order_id ──► orders.order_id
order_details.product_id ──► products.product_id
orders.customer_id ──► customers.customer_id
orders.employee_id ──► employees.employee_id
products.category_id ──► categories.category_id
products.supplier_id ──► suppliers.supplier_id
employees.manager_id ──► employees.employee_id (a self-reference)A first look
SELECT * returns every column. The categories table is small enough to show completely:
SELECT * FROM categories;+-------------+-----------+-------------------------------------+
| category_id | name | description |
+-------------+-----------+-------------------------------------+
| 1 | Beverages | Coffee, tea, juices and soft drinks |
| 2 | Bakery | Bread, cakes and pastries |
| 3 | Dairy | Milk, cheese and yogurt |
| 4 | Produce | Fresh fruit and vegetables |
| 5 | Snacks | Chips, nuts and chocolate |
| 6 | Household | NULL |
+-------------+-----------+-------------------------------------+
Products reference a category and a supplier by id. Here are the first six:
SELECT product_id, name, category_id, supplier_id, unit_price, units_in_stock
FROM products
WHERE product_id <= 6;+------------+----------------------+-------------+-------------+------------+----------------+
| product_id | name | category_id | supplier_id | unit_price | units_in_stock |
+------------+----------------------+-------------+-------------+------------+----------------+
| 1 | Espresso Beans 1kg | 1 | 1 | 24.50 | 40 |
| 2 | Earl Grey Tea | 1 | 1 | 6.75 | 85 |
| 3 | Orange Juice 1L | 1 | 4 | 3.20 | 60 |
| 4 | Sparkling Water 6x1L | 1 | 4 | 4.99 | 0 |
| 5 | Sourdough Loaf | 2 | 2 | 4.80 | 25 |
| 6 | Butter Croissant | 2 | 2 | 1.60 | 120 |
+------------+----------------------+-------------+-------------+------------+----------------+
Orders and order lines
An order on its own only says who ordered when. The products are in order_details, one row per product per order. The unit_price is copied into the order line because prices change over time, while an old order must keep the price the customer actually paid. discount is a fraction: 0.10 means 10 % off.
SELECT * FROM orders WHERE order_id IN (1, 8, 20);
SELECT * FROM order_details WHERE order_id = 1;+----------+-------------+-------------+------------+--------------+------------+
| order_id | customer_id | employee_id | order_date | shipped_date | status |
+----------+-------------+-------------+------------+--------------+------------+
| 1 | 1 | 4 | 2025-01-05 | 2025-01-07 | delivered |
| 8 | 2 | 4 | 2025-02-22 | NULL | cancelled |
| 20 | 15 | 5 | 2025-05-28 | NULL | processing |
+----------+-------------+-------------+------------+--------------+------------+
+----------+------------+----------+------------+----------+
| order_id | product_id | quantity | unit_price | discount |
+----------+------------+----------+------------+----------+
| 1 | 1 | 1 | 24.50 | 0.00 |
| 1 | 6 | 4 | 1.60 | 0.00 |
| 1 | 9 | 2 | 1.45 | 0.00 |
+----------+------------+----------+------------+----------+
The status of an order is one of delivered, shipped, processing or cancelled. Orders that haven't left the warehouse yet have a NULL shipped_date.
Facts worth remembering
These details make good test cases, and several lessons rely on them:
- Customers George Brown (7) and Mia Jensen (13) have never placed an order.
- Products Sparkling Water 6x1L (4) and Rye Crackers (8) have never been sold. Both are out of stock (
units_in_stock = 0) and Rye Crackers isdiscontinued. - Three customers have no e-mail address and Ivan Petrov has no city.
- Employee Grace Hopper is the CEO and has no manager (
manager_idis NULL). Only the three sales reps (4, 5, 6) handle orders. - All dates are fixed between 2019 and mid-2025, so results never change.
SELECT employee_id, first_name, last_name, title, manager_id
FROM employees;+-------------+------------+-----------+-------------------+------------+
| employee_id | first_name | last_name | title | manager_id |
+-------------+------------+-----------+-------------------+------------+
| 1 | Grace | Hopper | CEO | NULL |
| 2 | Alan | Turing | Sales Manager | 1 |
| 3 | Ada | Byron | Warehouse Manager | 1 |
| 4 | Linus | Berg | Sales Rep | 2 |
| 5 | Maya | Lopez | Sales Rep | 2 |
| 6 | Omar | Haddad | Sales Rep | 2 |
| 7 | Tom | Wilson | Packer | 3 |
| 8 | Sara | Kim | Packer | 3 |
+-------------+------------+-----------+-------------------+------------+
Note: The full script that creates this database is a single SQL file of
CREATE TABLEandINSERTstatements. You will learn to write both kinds of statements in this course, and by the end you could write the whole script yourself.
Test yourself
Which table tells you which products were in order 5?
- orders
- products
- order_details
- categories
Why does order_details have its own unit_price column?
- To save a join
- Because the product's current price may change, but an old order must keep the price paid
- Because
productshas no price - MySQL requires it
What does employees.manager_id refer to?
- customers.customer_id
- orders.employee_id
- employees.employee_id
- Nothing; it is free text