SQL and Databases
Write real SQL from your first lesson, on a fresh PostgreSQL database in your browser that you can’t break. Filter, sort, summarise and join, then design and build databases of your own.
- 10 modules, 64 lessons
- About 40 hours
- 10 projects and a capstone
- Module 1 is open now, and free
Aligned to the SQL standard (ISO/IEC 9075) and ACM CS2023 · Lessons save for offline
Module 1 is open. The other modules are being written and reviewed by our instructors, and each one opens as it’s ready.
By the end, you’ll be able to
- Explain what a database is, how tables store data, and why apps and analysts use them.
- Write SELECT queries that filter, sort, calculate and summarise data.
- Combine tables with joins, subqueries and common table expressions.
- Change data safely with INSERT, UPDATE, DELETE and transactions.
- Design a relational database from requirements: tables, keys, relationships and normalisation.
- Build and change schemas with constraints, indexes and views.
- Make queries faster, prevent SQL injection, and control who can see what.
- Answer real business questions with window functions and reporting queries.
The syllabus
Tap a module to see its lessons
1Databases and your first query6 lessons · about 1 hourFree
What a database is, how tables work, and your first queries: choosing, filtering and sorting.
- What a database is
- Tables, rows and columns
- Your first SELECT
- Choosing columns
- Filtering with WHERE
- Sorting and limiting
Project: Answer ten questions about a bookshop's stock
2Filtering like a pro7 lessons plannedComing soon
Sharper questions: AND and OR, ranges, text search, missing data and CASE.
- AND, OR and NOT
- Ranges with BETWEEN and IN
- Searching text with LIKE
- NULL and missing data
- Calculated columns
- CASE
- Common mistakes
Project: Find the customers a shop should contact
3Summarising data6 lessons plannedComing soon
Turn rows into answers: counts, totals, averages, groups and dates.
- COUNT, SUM, AVG, MIN and MAX
- GROUP BY
- HAVING
- DISTINCT
- Dates and times
- Rounding and formatting
Project: A sales summary by month and product
4Joining tables7 lessons plannedComing soon
Combine tables with keys and joins, and avoid the classic join mistakes.
- Why data lives in many tables
- Primary and foreign keys
- INNER JOIN
- LEFT JOIN
- Joining three tables
- Self joins
- Join mistakes
Project: One report from orders, customers and products
5Subqueries and CTEs6 lessons plannedComing soon
Queries inside queries, common table expressions, EXISTS and UNION.
- Subqueries in WHERE
- Subqueries in FROM
- Common table expressions
- EXISTS
- UNION and friends
- Window functions: a first look
Project: Top sellers and repeat customers
6Changing data6 lessons plannedComing soon
Insert, update and delete safely, with transactions and constraints.
- INSERT
- UPDATE
- DELETE
- Transactions
- Constraints that protect data
- Upserts
Project: Run a stock update safely in a transaction
7Designing a database7 lessons plannedComing soon
Design tables from real requirements: keys, relationships and normalisation.
- From requirements to tables
- Data types
- Keys and relationships
- Normalisation
- Many-to-many tables
- Naming and conventions
- Diagrams (ERDs)
Project: Design a database for a library
8Building and changing schemas6 lessons plannedComing soon
Create and change tables, and add indexes, views and migrations.
- CREATE TABLE
- ALTER TABLE
- Indexes
- Views
- Migrations
- Seed data
Project: Build the library database, with indexes and a view
9Performance and security6 lessons plannedComing soon
Faster queries, no SQL injection, the right permissions and safe personal data.
- How queries run: EXPLAIN
- Indexes that help
- SQL injection
- Users, roles and permissions
- Backups
- Privacy and data protection
Project: Speed up slow queries and lock down access
10SQL for analysis7 lessons plannedComing soon
Window functions, rankings, running totals and the reports analysts write every week.
- Window functions
- Ranking and running totals
- Pivoting
- Cleaning messy data
- Cohorts and funnels
- Reporting queries
- Where to go next
Project: A monthly report with ranking and running totals
Some of what you’ll build
Module 4 · Coming soon
One report from orders, customers and products
Module 7 · Coming soon
Design a database for a library
Module 10 · Coming soon
A monthly report with ranking and running totals