Introduction
Overview
Behind almost every app you use there is a database. Your bank balance, your online orders, the songs in a playlist, the stock levels in a warehouse, the patients booked into a clinic — all of it lives in tables, and the language used to read and change those tables is SQL.
SQL (pronounced “S-Q-L” or “sequel” — both are fine) is over fifty years old and more in demand than ever. Developers use it to build applications, analysts use it to answer business questions, data engineers use it to build pipelines, and product managers use it to check their own numbers instead of waiting for someone else. If you work with data in any form, SQL is one of the highest-value skills you can learn.
This course takes you from your very first query to the techniques professionals use every day: filtering and sorting, joining tables, summarising millions of rows, window functions, safe changes with transactions, designing tables, speeding up queries with indexes, and working with JSON. You finish by designing, loading, querying and tuning a database of your own.
What SQL looks like
Here is a complete SQL query. Even before you’ve learned a single rule, you can probably guess what it does:
SELECT name, price
FROM products
WHERE price < 10
ORDER BY price; name | price
-----------------+-------
Chamomile Calm | 8.00
Assam Breakfast | 9.50
(2 rows)It reads almost like English: select the name and price from the products table, where the price is under 10, ordered by price. The database replies with a small table of exactly those rows.
That’s the shape of everything you’ll do in SQL. You describe the result you want; the database hands it back.
How a database answers a query
Most programming languages are imperative: you write the steps — loop over these items, check this condition, add to that list. SQL is declarative: you write what you want, not how to get it.
When PostgreSQL receives your query, a component called the planner considers different ways to produce the answer: read the whole table, or jump straight to the matching rows using an index? Join these two tables first, or those two? It estimates the cost of each plan and picks the cheapest. The same short query can run in microseconds on a table of ten rows or ten billion rows, and you never have to rewrite it.
Two consequences are worth remembering from the start:
- Every query returns a table. Ask for one number — “how many customers do we have?” — and you get a table with one row and one column. That’s what makes SQL composable: the output of one query can be the input of another.
- The database does the heavy lifting. Rather than downloading a million rows into a spreadsheet and filtering them by hand, you send a few lines of SQL and get back only the answer.
Where SQL is used
- Application back ends. When you place an order on a website, code on the server runs SQL like
INSERT INTO orders …andUPDATE products SET stock = stock - 1 …. - Analytics and reporting. “What were sales by country last quarter?” is one SQL query. Dashboards in tools like Metabase, Looker, Tableau and Power BI are built on SQL.
- Data engineering. Data warehouses such as Snowflake, BigQuery, Redshift and Databricks are all queried with SQL dialects.
- Everywhere else. SQLite, a tiny SQL database, runs inside every iPhone and Android phone and in the major web browsers. Many spreadsheets, logging tools and even AI agents speak SQL.
Why PostgreSQL?
SQL is a standard, and every database implements it with small differences — called dialects. This course uses PostgreSQL (often just “Postgres”): free, open source, famously standards-compliant, and for several years running the database developers report using most in the Stack Overflow survey. PostgreSQL 19, released in November 2026, is the current version and the one every example in this course was run against.
What you learn here transfers almost entirely. SELECT, WHERE, JOIN, GROUP BY, window functions and transactions work the same way in MySQL, SQL Server, Oracle, SQLite and the cloud warehouses. Where a feature is PostgreSQL-specific, or a common database does it differently, the lesson says so.
The Bean & Leaf shop
Instead of a new toy table in every lesson, the whole course uses one realistic database: Bean & Leaf, a small online shop selling coffee, tea and brewing equipment. It has customers in several countries, products in categories, orders with several items each, and a small team of employees with managers. It’s small enough to read in one screen per table, and rich enough to ask real business questions:
- Which products have never been ordered?
- Who are our best customers, and which city do they live in?
- How much revenue did we make each month, and is it growing?
- Which orders are still waiting to be shipped?
You’ll download it and load it into your own PostgreSQL in Setting up PostgreSQL, two lessons from now: shop.sql.
What you need
Nothing beyond a computer. No programming experience is required — SQL is often people’s first language. If you already know a little Python or JavaScript, the final chapter shows how to run SQL safely from application code.
How the course works
Every lesson explains one idea with real queries, diagrams of what the database is doing, and the exact output PostgreSQL returns. All of those outputs were produced by running the lesson against the Bean & Leaf database — what you see is what you’ll get. Each lesson ends with an exercise; type your answer, run it, and compare with the solution.
Tip: type the queries yourself rather than copying them. SQL is learned through the fingers — the small mistakes you make along the way (a missing comma, a misspelt column) teach you to read error messages, which is half the skill.
Your first answer from a database
Bean & Leaf, the online coffee and tea shop used throughout this course, wants a list of its cheap products for a "treats under $10" email. Write a query that returns the name and price of every product that costs less than 10, cheapest first. You don't need to know the syntax yet — the starter is almost complete, and the lesson shows the same query. Run it and check you get two rows: Chamomile Calm at 8.00 and Assam Breakfast at 9.50.
-- Fill in the column names and the condition.
SELECT ___, ___
FROM products
WHERE ___
ORDER BY price;SELECT name, price
FROM products
WHERE price < 10
ORDER BY price;Summary
- SQL (Structured Query Language) is the standard language for asking questions of relational databases and changing the data in them.
- SQL is declarative: you describe the result you want, and the database works out how to produce it.
- Every query returns a table — rows and columns — even when the answer is a single number.
- This course uses PostgreSQL 19, and almost everything you learn carries over to MySQL, SQLite, SQL Server and cloud warehouses.
- All lessons use one realistic database — the Bean & Leaf online shop — which you can download and load yourself.