Tutorials › SQL Tutorial › The Skope Shop Database

The Skope Shop Database

9 min read · Lesson 2 of 24

Before writing real queries, it helps to know the data you are querying. Every example in this tutorial uses the Skope Shop database: a small business that sells computer accessories and office equipment to companies across East Africa.

The database has four tables:

TableOne row is…Rows
customersa business that buys from Skope Shop12
productsan item Skope Shop sells12
ordersone order placed by a customer12
order_itemsone product line inside an order20

The customers table

Example SQL
SELECT * FROM customers;
Try it Yourself »
ColumnMeaning
customer_ida unique number for each customer (the primary key)
namethe business name, e.g. Lakeside Books
contactthe person we deal with
city, countrywhere the customer is based
joinedthe date they became a customer, written as YYYY-MM-DD

Most customers are in Kenya, but there are also customers in Uganda, Tanzania and Rwanda. Look carefully and you will see that one customer, Nyeri Stationers, has no country recorded. That empty value is called NULL, and it gets its own lesson: NULL Values.

The products table

Example SQL
SELECT * FROM products;
Try it Yourself »
ColumnMeaning
product_idunique number for each product
nameproduct name
categoryAccessories, Displays, Video, Audio, Storage or Office
priceprice of one unit in Kenya shillings (KSh)
stockhow many units are in the warehouse

Notice the Bluetooth Speaker has a stock of 0. Zero is a real value (we know there are none), which is different from NULL (we don't know).

The orders table

Example SQL
SELECT * FROM orders;
Try it Yourself »
ColumnMeaning
order_idunique order number (they start at 101)
customer_idwhich customer placed the order
order_datewhen the order was placed
statuspending, shipped, delivered or cancelled

The customer_id column here is a foreign key: it points to a row in the customers table. Order 101 has customer_id 1, which means it was placed by Lakeside Books.

The order_items table

An order can contain several different products, so the products in each order are stored in a separate table, one row per product line:

Example SQL
SELECT * FROM order_items;
Try it Yourself »
ColumnMeaning
item_idunique number for each line
order_idthe order this line belongs to (points to orders)
product_idthe product bought (points to products)
quantityhow many units

For example, the first two rows say that order 101 contained 2 Laptop Stands (product 1) and 2 Wireless Mice (product 2).

How the tables connect

The tables form a chain:

customers --< orders --< order_items >-- products
  • One customer can have many orders.
  • One order can have many order items.
  • One product can appear in many order items.

Splitting data like this avoids repeating information. The customer's city is stored once in customers, not copied into every order. If the customer moves, you update one row. Designing tables this way is called normalisation.

To answer a question such as "which products did Savannah Tech buy?", you combine tables using a join. That comes later in INNER JOIN. For now, here is a sneak preview so you can see where we are heading:

Example SQL
SELECT customers.name, orders.order_id, orders.status
FROM customers
JOIN orders ON orders.customer_id = customers.customer_id;
Try it Yourself »
Tip: Keep this page open in another tab while you work through the tutorial. Knowing which columns live in which table is half of writing good SQL.
Note: Each Try it Yourself run loads a fresh copy of the database, so any changes you make (inserts, updates, deletes) disappear on the next run.
Exercise

Show all rows from the table that stores order lines.

SELECT * FROM ;
Sign in or create a free account to track progress, earn XP, badges and a certificate.