SQL
The language for talking to databases
Learn how databases are organised and write SQL queries to select, filter, sort, group and join data. By the end you will create your own tables, change data safely and use indexes, views and transactions. Every example can be run right inside the lesson against a practice database.
Course content
SQL basics
BeginnerWhat a database is, how to pick data with SELECT and how to filter it with WHERE.
- 1Databases and tablesFind out what a database is, how tables are built from rows and columns, and how keys link tables together.12 min
- 2SELECT and column aliasesPick the columns you need, calculate new values on the fly, give columns aliases and remove duplicates with DISTINCT.14 min
- 3WHERE: filtering rowsUse WHERE to keep only the rows you need: comparison operators, AND, OR, NOT and why parentheses matter.15 min
Filtering, sorting and totals
BeginnerPrecise filters with LIKE, IN, BETWEEN and NULL, sorting with ORDER BY, and totals with aggregate functions.
- 4LIKE, IN, BETWEEN and IS NULLLearn to search by pattern (LIKE), match a list of values (IN), pick a range (BETWEEN) and handle missing data (NULL).16 min
- 5ORDER BY and LIMIT: sorting and limitingSort results by one or more columns, pick the top N rows, split results into pages and learn how different DBMSs do it.14 min
- 6Aggregate functions: COUNT, SUM, AVG, MIN, MAXTurn many rows into one number: count rows, add up values and find the average, the minimum and the maximum.14 min
Grouping and joining tables
IntermediateGroup reports with GROUP BY and HAVING, data from several tables with JOIN, and subqueries.
- 7GROUP BY and HAVING: totals per groupSplit rows into groups, calculate aggregates for each group and filter groups with HAVING.16 min
- 8JOIN: combining tablesCombine data from several tables with INNER JOIN and LEFT JOIN, find rows without a match and group after joining.18 min
- 9SubqueriesWrite a query inside a query: subqueries in WHERE, SELECT and FROM, IN, EXISTS, correlated subqueries and the WITH clause.18 min
Changing data and designing databases
AdvancedINSERT, UPDATE and DELETE, creating tables with constraints, indexes, views and transactions.
- 10INSERT, UPDATE, DELETE: changing dataAdd new rows to a table, change existing rows and delete the ones you don't need — and learn to do it safely.16 min
- 11CREATE TABLE: data types and constraintsCreate your own tables, choose the right column types and keep bad data out with PRIMARY KEY, NOT NULL, UNIQUE, CHECK, DEFAULT and FOREIGN KEY.18 min
- 12Indexes, views and transactionsSpeed up searches with indexes, give complex queries a name with views and make changes all-or-nothing with transactions.18 min
Advanced SQL
AdvancedWindow functions, CTEs and recursive queries, conditional logic with CASE, text, date and math functions, set operations and advanced joins.
- 13Window functionsRank rows, number them within groups, build running totals and compare with the previous row without losing any rows: ROW_NUMBER, RANK, DENSE_RANK, SUM() OVER, PARTITION BY, LAG and LEAD.22 min
- 14CTEs: WITH and recursive queriesBreak a complex query into named steps, chain several CTEs together and build number series and hierarchies with recursive CTEs.20 min
- 15CASE and conditional logicWrite “if… then…” inside a query with CASE WHEN, control NULL with COALESCE and NULLIF, and pivot a table with conditional aggregation.18 min
- 16String, date and math functionsCut, join and search text, calculate with dates and round numbers in SQLite, and learn the MySQL and PostgreSQL equivalent of each function.20 min
- 17Set operations and advanced joinsCombine and compare query results with UNION, UNION ALL, INTERSECT and EXCEPT; join a table to itself, build every combination with CROSS JOIN and find what is missing with NOT EXISTS.20 min
Databases at a professional level
UniversityDatabase design and normalisation, transactions and concurrency, indexes and query optimisation, PostgreSQL and MySQL in practice, and data analysis with SQL.
- 18Database design and normalisationBuild an ER model, determine the cardinality of relationships, find functional dependencies and decompose tables step by step into 1NF, 2NF, 3NF and BCNF.30 min
- 19Transactions and concurrencyLearn how ACID is achieved, which anomalies concurrent transactions cause, and how isolation levels, locks, MVCC and deadlocks work.30 min
- 20Query optimisation and indexesLearn how a B-tree index works, how to read a query plan, how to write index-friendly (sargable) conditions, what composite and covering indexes are, and when an index does harm.30 min
- 21PostgreSQL and MySQL in practiceMoving to server DBMSs: data types, IDENTITY and AUTO_INCREMENT, JSON columns, differences from SQLite, users and privileges, and backups.30 min
- 22Data analysis with SQLCalculate business metrics with SQL: average order value, cohorts and retention, funnel conversion, medians and percentiles, and finally an ABC analysis project on the practice data.30 min