SQL and databases, from zero to interviews

A free SQL and DBMS course at three levels, Basic, Intermediate and Advanced: SELECT, joins, GROUP BY, subqueries, window functions, CTEs, indexes and transactions, plus the DBMS theory exams ask (ER diagrams, normalisation, ACID, serializability and recovery) and 50 SQL interview problems. Every query runs on real Postgres in the browser, on a phone too.

Basic

What a database is, then SQL from your first SELECT to joins and subqueries.

Module 1: What a database is

Why we keep data in a database, not a spreadsheet: tables, rows, keys, and what a DBMS does for you.

Module 2: Your first queries

Ask the database questions with SELECT: pick columns, filter rows with WHERE, handle NULL and sort the answer.

Module 3: Functions and expressions

Work with text, numbers and dates inside a query, and turn values into categories with CASE.

Module 4: Aggregates and GROUP BY

Summarise thousands of rows into a report: totals, averages and counts per group, filtered with HAVING.

Module 5: Joins

Combine tables: inner and outer joins, self joins, and finding the rows that have no match.

Module 6: Subqueries and set operations

Put a query inside a query, test for existence, and combine result sets with UNION, INTERSECT and EXCEPT.

Intermediate

Design tables and change data, model with ER diagrams, normalise, and master window functions and CTEs.

Module 7: Creating tables

Design tables that protect their own data: types, primary and foreign keys, UNIQUE, CHECK and ALTER TABLE.

Module 8: Changing data

Insert, update and delete rows safely, return what changed, and upsert with ON CONFLICT.

Module 9: ER modelling

Turn a real-world problem into an ER diagram and then into tables: entities, relationships and cardinality.

Module 10: Normalization

Spot redundancy and anomalies, find functional dependencies and keys, and normalise to 3NF and BCNF.

Module 11: Window functions

Rank, number and compare rows without collapsing them: ROW_NUMBER, RANK, LAG and running totals.

Module 12: CTEs and recursive queries

Write long queries as readable steps with WITH, walk hierarchies with recursive CTEs, and build reports.

Advanced

Transactions and isolation, indexes and query plans, views and triggers, and how a DBMS works inside.

Module 13: Transactions and concurrency

Keep money correct when things fail or run at once: ACID, isolation levels, MVCC, locks and deadlocks.

Module 14: Indexes and query plans

Make slow queries fast: how B+ tree indexes work, reading EXPLAIN, composite indexes and when an index can't help.

Module 15: Views, functions and security

Package logic in the database: views, PL/pgSQL functions, triggers, roles and GRANT, and stopping SQL injection.

Module 16: Inside the DBMS

The theory exams ask: relational algebra, storage and B+ trees, serializability and locking protocols, logging and recovery.

Module 17: Beyond one database

What changes at scale: replication, partitioning and sharding, CAP, and when to pick NoSQL over SQL.

Interview practice

Classic SQL interview problems, each graded on hidden data.

Interview pack: SQL interview problems

Fifty classic SQL interview questions, from the second-highest salary to login streaks, each graded on hidden data.

Practice and reference