Quick answer: This is a free, step-by-step SQL course in 40 short lessons, in a fixed order. You learn SQL on PostgreSQL with one small practice database (an online shop), and every lesson shows real queries, the real result, exercises with solutions, and the mistakes beginners usually make. Start with Lesson 1 and follow the “Next lesson” link at the end of each page.
The course goes from “what is a database?” to joins, window functions, database design, indexes, transactions and two projects. Where MySQL, SQLite or SQL Server write something differently, the lesson says so. New lessons are added in order; 25 of 40 are live now, and lessons that are not published yet are listed without a link.
Table of Contents
Who this SQL course is for
- Complete beginners who have never written a query.
- Data analysts, data scientists and data engineers who need SQL every day.
- Backend developers who want to understand the database behind their app.
You need a computer (Windows, macOS or Linux) and about 30 to 60 minutes per lesson. PostgreSQL and every other tool used here are free.
How to use this course
- Install PostgreSQL and load the shop practice database in Lesson 3. Every later lesson uses it.
- Type each query yourself, run it, and compare your result with the result shown.
- Do the “Try it yourself” exercises before you look at the solutions.
- Finish each level with its practice set or project before you move on.
SQL course outline
Level 1: Foundations
Module 1: Databases and setup
- Lesson 1: What Is a Relational Database? Tables, Rows, Columns and Keys
- Lesson 2: PostgreSQL vs MySQL vs SQLite vs SQL Server: Which SQL to Learn First
- Lesson 3: Install PostgreSQL and Load a Sample Database for SQL Practice
Module 2: Querying one table
- Lesson 4: SQL SELECT Statement: Columns, Aliases, DISTINCT and LIMIT
- Lesson 5: SQL WHERE Clause: Filter Rows with AND, OR, IN, BETWEEN and LIKE
- Lesson 6: SQL NULL Values: IS NULL, COALESCE and Three-Valued Logic
- Lesson 7: SQL ORDER BY: Sorting, NULLS FIRST/LAST and Paging with LIMIT/OFFSET
- Lesson 8: SQL CASE WHEN, CAST and Common String and Date Functions
Level 2: Core SQL
Module 3: Aggregation
- Lesson 9: SQL Aggregate Functions: COUNT, SUM, AVG, MIN and MAX
- Lesson 10: SQL GROUP BY and HAVING
- Lesson 11: SQL Order of Execution: Why Aliases and Aggregates Fail in WHERE
Module 4: Joins
- Lesson 12: SQL INNER JOIN Explained
- Lesson 13: SQL LEFT JOIN, RIGHT JOIN and FULL OUTER JOIN
- Lesson 14: SQL Self Join, CROSS JOIN, Semi-Joins and Anti-Joins
- Lesson 15: SQL UNION vs UNION ALL, INTERSECT and EXCEPT
Module 5: Creating and changing data
- Lesson 16: SQL CREATE TABLE: Data Types and Constraints
- Lesson 17: SQL INSERT, UPDATE and DELETE: Change Data Safely with RETURNING
- Lesson 18: SQL Upsert: INSERT … ON CONFLICT and MERGE
- Lesson 19: SQL Transactions: BEGIN, COMMIT, ROLLBACK and SAVEPOINT
Level 3: Intermediate
Module 6: Subqueries and CTEs
- Lesson 20: SQL Subqueries: Scalar, IN, EXISTS and Correlated Subqueries
- Lesson 21: SQL CTE: WITH Clause and CTE vs Subquery
- Lesson 22: SQL Recursive CTE: WITH RECURSIVE for Hierarchies, Trees and Date Series
- Lesson 23: SQL Views: CREATE VIEW and Materialized Views in PostgreSQL
Module 7: Window functions
- Lesson 24: SQL Window Functions: OVER and PARTITION BY
- Lesson 25: Ranking and top-N per group: ROW_NUMBER, RANK, DENSE_RANK (coming soon)
- Lesson 26: LAG, LEAD, running totals and window frames (ROWS vs RANGE) (coming soon)
- Lesson 27: Window functions practice problems
Module 8: Database design
- Lesson 28: ER modeling: entities, relationships and keys (coming soon)
- Lesson 29: Normalization: 1NF, 2NF, 3NF and BCNF with examples (coming soon)
- Lesson 30: Normalization vs denormalization (OLTP vs analytics) (coming soon)
Level 4: Advanced
Module 9: Performance
- Lesson 31: How database indexes work (B-tree, composite, covering, partial; PG index types) (coming soon)
- Lesson 32: Reading EXPLAIN and EXPLAIN ANALYZE in PostgreSQL (coming soon)
- Lesson 33: SQL query optimization checklist (sargable filters, statistics, join strategies) (coming soon)
Module 10: Concurrency
- Lesson 34: Isolation levels, locks and deadlocks (coming soon)
- Lesson 35: PostgreSQL JSONB and arrays for semi-structured data (coming soon)
Level 5: Production SQL and projects
Module 11: Production SQL
- Lesson 36: Preventing SQL injection: parameterized queries, roles and GRANT (coming soon)
- Lesson 37: Table partitioning for large tables (coming soon)
Module 12: Projects
- Lesson 38: Project: sales analytics with SQL (cohorts, retention, funnels) (coming soon)
- Lesson 39: Project: design and build an e-commerce database end to end (coming soon)
- Lesson 40: SQL interview questions with worked answers (coming soon)
SQL first, then MongoDB
This page used to be a combined SQL and MongoDB roadmap. The advice has not changed: learn SQL first. Relational databases such as PostgreSQL and MySQL are what most data and backend jobs use, and the ideas you learn here (tables, keys, filtering, joins, indexes, transactions) make document databases much easier to understand later. MongoDB is a document database: it stores JSON-like documents instead of rows in tables. Learn it after this course if your work needs flexible, nested data; Lesson 35 (JSONB in PostgreSQL) shows how far a relational database can go with semi-structured data first.
Frequently asked questions
Is this SQL course free?
Yes. Every lesson is free to read on this site, and PostgreSQL, the practice database and the tools used in the course are free.
Which SQL should I learn first?
This course uses PostgreSQL, because it is free, follows the SQL standard closely and is widely used. The basics carry over to MySQL, SQLite and SQL Server; Lesson 2 compares them, and later lessons point out the differences that matter.
How long does it take to learn SQL?
There are 40 lessons, and most take 30 to 60 minutes with the exercises. The first two levels (about 19 lessons) cover the SQL most analyst jobs ask for, so at one lesson a day you can be productive in about three weeks.
Should beginners learn SQL or MongoDB first?
SQL first. It is needed in far more jobs, and it teaches the data ideas that make MongoDB and other NoSQL databases easier later.
Do I need programming experience to learn SQL?
No. SQL is a small language of its own, and this course assumes no programming background. If you also want Python for data work, the Python course starts from zero too.
Start the course
Begin with Lesson 1: What is a relational database?.





