SQL Quest

Lessons, hints, explained solutions, the in-browser PostgreSQL editor and practice answer checks in your browser are available. Graded assessments, recorded progress from answer checks and new certificates aren't available yet.

Starter shop

Corner Market (fictional) · 3 tables · 46 rows · version 2

Open in the playground

Three small tables you can read in full: customers, products and orders. Every order belongs to one customer and is for one product. Use it to learn SELECT, WHERE, ORDER BY and your first joins without being overwhelmed by data.

Relationships

customers12PKcustomer_idcustomer_namecityemailjoined_onproducts10PKproduct_idproduct_namecategorypricestockorders24PKorder_idFKcustomer_idFKproduct_idorder_datequantitystatus
Arrows point from a foreign key to the table it references. PK = primary key, FK = foreign key. Numbers are row counts.

Sample queries

Customers in Riyadh
SELECT customer_name, city
FROM customers
WHERE city = 'Riyadh';
Products by price
SELECT product_name, price
FROM products
ORDER BY price DESC;
Orders with customer names
SELECT o.order_id, c.customer_name, o.order_date
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id
ORDER BY o.order_date;

Data dictionary

customers

12 rows · primary key (customer_id)

People who have registered with the shop.

ColumnTypeNull?KeyDescription
customer_idintegerno PKUnique number for each customer.
customer_nametextnoFull name.
citytextyesCity of the delivery address. NULL when the customer has not told us.
emailtextyesEmail address. NULL when not provided.
joined_ondatenoDate the customer registered.

products

10 rows · primary key (product_id)

Items the shop sells.

ColumnTypeNull?KeyDescription
product_idintegerno PKUnique number for each product.
product_nametextnoName shown in the shop.
categorytextnoProduct category.
pricenumeric(12,2)noCurrent price in SAR.
stockintegernoUnits in stock right now.

orders

24 rows · primary key (order_id)

One row per order. Each order is for a single product.

ColumnTypeNull?KeyDescription
order_idintegerno PKUnique number for each order.
customer_idintegerno customers.customer_idWho placed the order.
product_idintegerno products.product_idWhat was ordered.
order_datedatenoDate the order was placed.
quantityintegernoNumber of units ordered.
statustextnoprocessing, shipped, delivered or cancelled.