Why SQL is essential
Most analytics work happens where the data lives:
- Relational databases (PostgreSQL, MySQL, SQLite)
- Data warehouses (BigQuery, Snowflake, Redshift)
SQL is used to:
- Retrieve data efficiently
- Aggregate metrics (DAU, revenue, churn)
- Join multiple tables (users + orders + events)
Core mental model
- Data is stored in tables.
- A query reads rows/columns and returns a result set.
SELECT *
FROM users
LIMIT 10;Typical analytics tables
users(user_id, created_at, country, plan)orders(order_id, user_id, order_ts, amount)events(user_id, event_ts, event_name, device)
What you’ll learn in this phase
SELECT,WHERE,ORDER BY,LIMIT- Aggregations:
COUNT,SUM,AVG GROUP BY,HAVING- Joins
- Window functions
- CTEs
- Using SQL from Python (pandas)
Where SQL fits in an analytics workflow
You rarely run one query in isolation. The usual shape of the work is: raw tables live in a database, a query filters and reshapes them, and the result lands somewhere you can chart, model, or share.
flowchart LR A["users table"] --> D["SQL query"] B["orders table"] --> D C["events table"] --> D D --> E["Result set (rows + columns)"] E --> F["pandas DataFrame / BI dashboard"]
The database never changes because you queried it — a SELECT just reads and returns rows.
That's what makes SQL safe to explore with: you can run the same query a hundred times while
you're figuring out the right filter, and nothing gets damaged.
SQLite: a database in a single file
You don't need a server to practice SQL. SQLite (Python's built-in sqlite3 module) stores an
entire database in one file — or even in memory — which makes it perfect for learning and for
the exercises on this page.
import sqlite3
conn = sqlite3.connect(":memory:")
conn.execute("CREATE TABLE users (user_id INTEGER, country TEXT, plan TEXT)")
conn.executemany(
"INSERT INTO users VALUES (?, ?, ?)",
[(1, "IN", "free"), (2, "IN", "pro"), (3, "US", "pro")],
)
conn.commit()
rows = conn.execute("SELECT * FROM users").fetchall()
print(rows)[(1, 'IN', 'free'), (2, 'IN', 'pro'), (3, 'US', 'pro')]Check your understanding
What does a SELECT query do to the database?
That is why SQL is safe to explore: you can run the same query many times.
Show answer
A — It only reads and returns rows, leaving the data unchanged — That is why SQL is safe to explore: you can run the same query many times.
Which SQLite call creates a throwaway in-memory database in the lesson?
No file or server is needed, and nothing is left behind.
Show answer
A — sqlite3.connect(":memory:") — No file or server is needed, and nothing is left behind.
What does SELECT * FROM users LIMIT 10 return?
The star selects every column and LIMIT caps the number of rows.
Show answer
A — Ten users at most, with all columns — The star selects every column and LIMIT caps the number of rows.
Which table in the lesson holds amount and order_ts?
orders has order_id, user_id, order_ts and amount, while events holds event_name and device.
Show answer
B — orders — orders has order_id, user_id, order_ts and amount, while events holds event_name and device.
🧪 Try It Yourself
Exercise 1 – Create a table and read it back
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Filter rows with WHERE
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Load a query result into pandas
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Next
Head to SQL Basics (SELECT, WHERE, ORDER BY, LIMIT) to practice the four clauses you'll use in almost every query you ever write.