SQL Sample Database
All examples in this course use TAD Market, an imaginary online shop that sells coffee, groceries, gadgets, kitchen goods and books to cafes, studios and individual customers around the world. It is small enough to understand completely, but rich enough for joins, grouping and reports.
The tables
| Table | Rows | What it stores |
|---|---|---|
categories |
8 | Product categories (Beverages, Bakery, Dairy, …) |
suppliers |
8 | Companies that supply the products |
products |
30 | Items for sale, with price and stock |
customers |
25 | Shops and people who buy from TAD Market |
employees |
10 | Staff; manager_id points to another employee |
orders |
40 | One row per order, with dates and status |
order_items |
98 | The lines of each order: which product, how many, at what price |
Columns
| Table | Columns |
|---|---|
categories |
category_id, name, description |
suppliers |
supplier_id, name, contact, city, country |
products |
product_id, name, category_id, supplier_id, unit, price, stock |
customers |
customer_id, name, contact, email, city, country, joined |
employees |
employee_id, first_name, last_name, title, hire_date, manager_id, salary |
orders |
order_id, customer_id, employee_id, order_date, shipped_date, status |
order_items |
item_id, order_id, product_id, quantity, unit_price |
Each table has a primary key (the ..._id column named after the table) that identifies a row uniquely. Columns such as products.category_id or orders.customer_id are foreign keys: they hold the id of a row in another table. That is how the tables are linked:
categories ──< products >── suppliers
│
^
customers ──< orders >── employees ──┐
│ ^ │ manager_id
^ └───────┘
order_items(──< means "one to many": one category has many products, one order has many order items.)
Note:
order_items.unit_pricerecords the price charged when the order was placed (in TAD Market it equals the product's currentprice). An order line is worthquantity * unit_price.
A look at the data
SELECT * FROM categories;category_id | name | description
------------+-------------+------------------------------------
1 | Beverages | Coffee, tea, juices and soft drinks
2 | Bakery | Bread, pastries and cakes
3 | Dairy | Milk, cheese and yogurt
4 | Produce | Fresh fruit and vegetables
5 | Snacks | Chips, nuts and sweets
6 | Electronics | Small gadgets and accessories
7 | Home | Kitchen and household goods
8 | Books | Programming and cooking books
(8 rows)
SELECT * returns every column. Here are the first few products:
SELECT product_id, name, category_id, unit, price, stock
FROM products
ORDER BY product_id
LIMIT 6;product_id | name | category_id | unit | price | stock
-----------+-----------------+-------------+------------+-------+------
1 | Espresso Beans | 1 | 1 kg bag | 24.5 | 40
2 | Green Tea | 1 | 50 bags | 8.75 | 120
3 | Orange Juice | 1 | 1 L bottle | 3.2 | 75
4 | Sparkling Water | 1 | 6 x 500 ml | 4.6 | 0
5 | Chai Latte Mix | 1 | 500 g tin | 11 | 32
6 | Sourdough Loaf | 2 | 800 g | 5.5 | 25
(6 rows)
Things worth knowing
A few details of the data are deliberately "imperfect" so you can practise real-world situations:
- Some customers have no e-mail address — the
emailcolumn isNULLfor them. - Seven customers (for example 13 and 24) have never placed an order, and products 14 (Avocados) and 27 (Coffee Grinder) have never been sold. These matter for outer joins.
- Orders have a
statusofdelivered,shipped,processingorcancelled. Orders that have not shipped yet have aNULLshipped_date. - Dates are stored as text in ISO format
YYYY-MM-DD, which sorts correctly and works with SQLite's date functions. - Employees form a hierarchy: everyone except the CEO has a
manager_id.
SELECT employee_id, first_name, last_name, title, manager_id
FROM employees
ORDER BY employee_id;employee_id | first_name | last_name | title | manager_id
------------+------------+-----------+--------------------+-----------
1 | Grace | Holt | CEO | NULL
2 | Victor | Ames | Sales Manager | 1
3 | Lin | Zhou | Operations Manager | 1
4 | Rosa | Delgado | Sales Rep | 2
5 | Tom | Becker | Sales Rep | 2
6 | Aisha | Bello | Sales Rep | 2
7 | Marco | Ricci | Warehouse Lead | 3
8 | Hana | Sato | Support Specialist | 3
9 | Owen | Price | Sales Rep | 2
10 | Elena | Popescu | Data Analyst | 1
(10 rows)
Linking two tables
Here is a preview of a join — you will learn them properly later. It shows each order of customer 2 together with the customer's name:
SELECT o.order_id, c.name AS customer, o.order_date, o.status
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id
WHERE o.customer_id = 2
ORDER BY o.order_date;order_id | customer | order_date | status
---------+--------------+------------+-----------
21 | Bright Bytes | 2025-06-13 | delivered
25 | Bright Bytes | 2025-07-28 | processing
31 | Bright Bytes | 2025-08-11 | delivered
35 | Bright Bytes | 2025-09-11 | processing
(4 rows)
Tip: Keep this page open in another tab while you work through the course — the column list above is a handy reference.
Test yourself
Which table tells you which products were in an order?
- orders
- products
- order_items
- categories
What does orders.customer_id hold?
- The customer's name
- The id of a row in
customers(a foreign key) - A random number
- The number of orders of that customer
How is the employee hierarchy stored?
- In a separate managers table
- With
employees.manager_idpointing to another employee - With the
titlecolumn - It is not stored