Course Resources
Introduction
This page gathers what you will reach for during the course:
- documentation for SQLite and for other databases
- the course's dataset: its tables and how they connect
- how to study, and common mistakes
- what to do when a query fails
- a cheat sheet of clauses, functions and operators
Official Database Documentation
SQLite
The queries in this course run on SQLite. Its documentation is the reference for whatever a lesson leaves out:
- SQLite Documentation: the index of every page
- Query Language Understood by SQLite: every statement and clause
- Built-In Scalar SQL Functions: the functions a query can call
Other Databases
What you learn here carries over to other databases, and their documentation helps once you work with them:
| Database | Documentation |
|---|---|
| PostgreSQL | The SQL Language |
| MySQL | MySQL Documentation |
| Microsoft SQL Server | Transact-SQL Reference |
| Oracle Database | Database Documentation |
One Standard, Many Dialects
SQL is an international standard, ISO/IEC 9075, revised from time to time; its latest version is SQL:2023. Each database follows much of it, adds features of its own and leaves some out. PostgreSQL's documentation notes that "at the time of writing, no current version of any database management system claims full conformance to Core SQL:2023". So SELECT with WHERE, GROUP BY and ORDER BY reads the same everywhere, and where SQLite does something in its own way, the lessons say so.
Practice Database: Brazilian E-Commerce Dataset
About the Dataset
The Brazilian E-Commerce Public Dataset holds real orders placed through Olist, a Brazilian company that sells small shops' products on online marketplaces. On CodePeet it has 99,441 orders, placed from 4 September 2016 to 17 October 2018, in 9 tables. It has the gaps real data has: values that are missing, the same city written two ways, and 2 product categories with no English name.
Available Tables
| Table | Rows | One row is |
|---|---|---|
olist_customers_dataset | 99,441 | the customer of one order: city, state, zip code prefix |
olist_orders_dataset | 99,441 | an order: its status, its times, its customer |
olist_order_items_dataset | 112,650 | one item of an order: product, seller, price, freight |
olist_order_payments_dataset | 103,886 | one payment of an order: type, installments, amount |
olist_order_reviews_dataset | 100,000 | a review of an order: score, comment |
olist_products_dataset | 32,951 | a product: category, size, weight |
olist_sellers_dataset | 3,095 | a seller: city, state, zip code prefix |
olist_geolocation_dataset | 1,000,163 | a location for a zip code prefix: latitude, longitude, city |
product_category_name_translation | 71 | a category's name in Portuguese and in English |
Why Real Data?
- It has gaps. Some values are missing and some are written two ways; you learn to find both.
- Its tables are connected. Many questions need two or more of them.
- It has a business behind it. Each query answers something a shop would ask.
- It has size. About a hundred thousand orders, and a million rows of locations.
Table Relationships Overview
Key Relationships
Each link is a column two tables share, and a join matches rows on it:
| Tables | Joined on | What matches |
|---|---|---|
| orders and customers | customer_id | each order has its own customer row, 99,441 of each |
| order_items and orders | order_id | 112,650 items in 98,666 orders; 775 orders have none |
| order_payments and orders | order_id | 103,886 payments; 1 order has none |
| order_reviews and orders | order_id | every order has a review, and 555 have more than one |
| order_items and products | product_id | every item names one product |
| order_items and sellers | seller_id | every item names one seller |
| products and the translation | product_category_name | 71 of the 73 named categories have an English name |
| customers or sellers and geolocation | the zip code prefix | not a key: 52.6 location rows a prefix on average, so the join repeats rows |
The SQL Joins section of this course shows how to follow these links. In the diagram, each line is one of them:

Tips for Effective Learning
Active Practice
| Do this | Not this |
|---|---|
| Run every example | Only read the queries |
| Change a query and run it again | Copy it without knowing what each part does |
| Try each exercise before you run its worked query | Run the worked query first |
| Build a long query one part at a time | Take in the whole thing at once |
The Order a Query Runs In
You write SELECT first, but the database works in another order. SQLite's documentation and PostgreSQL's describe the same steps:
- FROM takes the rows of the tables.
- WHERE keeps the rows that pass its test.
- GROUP BY folds the rows into groups and works out the aggregates.
- HAVING keeps the groups that pass its test.
- SELECT works out the output columns.
- ORDER BY sorts the rows. Without it, in SQLite's words, "the order in which the rows are returned is undefined".
- LIMIT keeps the first ones.
Coding Order vs Execution Order goes through this step by step.
Common Beginner Mistakes
| Mistake | What happens | What to write |
|---|---|---|
| A plain column beside COUNT, with no GROUP BY | SQLite returns one row, and the plain column's value comes from "one of the input rows that form the aggregate": you cannot tell which. PostgreSQL refuses the query. | Group by the plain column |
| A condition on COUNT in WHERE | WHERE runs before the groups exist, so the query fails | Put it in HAVING |
| Text without quotes | customer_state = SP looks for a column named SP: no such column: SP | customer_state = 'SP' |
== for equals | SQLite accepts it; PostgreSQL answers operator does not exist: text == unknown | One = |
Getting Help
When a Query Fails
1. Read the error. The page shows the first line of SQLite's message, and it usually names the problem. Three you will meet often, as the page shows them:
no such column: customer_name: the table has no column of that name. Check its spelling, and which table you are reading.near "FROM": syntax error: SQLite stopped at the word in quotes. Look just before it: here, a comma before FROM.ambiguous column name: customer_id: two of the joined tables have that column. Say which one:o.customer_id.
2. Build it up. Start with SELECT and FROM and run it; add WHERE and run it again; then GROUP BY, and so on. The step that breaks the query is the one to look at.
3. Look at the data. A table's first rows:
SELECT * FROM olist_orders_dataset LIMIT 5;And the values a column holds:
SELECT DISTINCT order_status FROM olist_orders_dataset ORDER BY order_status;This one returns the 8 statuses an order has in this data: approved, canceled, created, delivered, invoiced, processing, shipped and unavailable.
4. Compare with a working example. Find the example closest to what you want in a lesson, and change it one part at a time.
Quick Reference Cheat Sheet
Basic Query Structure
SELECT column1, column2
FROM table_name
WHERE condition
GROUP BY column1
HAVING aggregate_condition
ORDER BY column1 DESC
LIMIT 10;
Common Aggregate Functions
| Function | What it gives | Example |
|---|---|---|
COUNT(*) | the number of rows | COUNT(*) |
COUNT(column) | the number of rows where the column is not NULL | COUNT(customer_id) |
SUM(column) | the total | SUM(price) |
AVG(column) | the average | AVG(review_score) |
MIN(column) | the smallest value | MIN(shipping_limit_date) |
MAX(column) | the largest value | MAX(shipping_limit_date) |
Common Operators
| Operator | Meaning | Example |
|---|---|---|
= | equal to | WHERE state = 'SP' |
!= or <> | not equal to | WHERE status != 'canceled' |
>, < | greater than, less than | WHERE amount > 100 |
>=, <= | greater or equal, less or equal | WHERE score >= 4 |
AND | both conditions true | WHERE a = 1 AND b = 2 |
OR | either condition true | WHERE a = 1 OR a = 2 |
IN | equal to one in a list | WHERE state IN ('SP', 'RJ') |
BETWEEN | in a range, both ends included | WHERE amount BETWEEN 10 AND 100 |
LIKE | matches a pattern | WHERE city LIKE 'sao%' |
IS NULL | has no value | WHERE email IS NULL |
Summary
What You Learned
- SQLite's documentation answers what a lesson leaves out; the other databases' documentation helps when you move to them.
- The course's database is real: 99,441 orders in 9 tables, with real gaps.
- Tables connect through shared columns. The diagram shows which, and one of them, the zip code prefix, is not a key.
- Run, change and build up queries one part at a time, and read the first line of an error when one fails.
Next Up
Continue to Course Roadmap & Structure, or go straight to What is SQL and What are Databases?.