Free course · No signup

Learn SQL from scratch

Go from your first SELECT to window functions, indexes, and transactions with short, practical lessons. Every lesson uses the same small shop database, so you can run each example yourself.

  • PostgreSQL
  • MySQL
  • SQLite
  • SQL Server
Lessons
23
Levels
4
Hours of reading
~3
Cost
Free

What you will learn

Each lesson explains one idea, shows the query, and then shows the result, so you can check your own work.

  • Query data with confidence

    Filter, sort, group, and summarize rows with SELECT, WHERE, ORDER BY, and aggregate functions.

  • Combine tables

    Use JOINs, UNION, and subqueries to answer questions that span several tables.

  • Clean and reshape data

    Work with text, dates, NULLs, and CASE expressions to prepare messy data for analysis.

  • Write advanced queries

    Use CTEs and window functions for rankings, running totals, and moving averages.

  • Design and protect databases

    Plan tables, add constraints and indexes, use transactions, and prevent SQL injection.

  • Prepare for interviews

    Finish with practice questions in the style of data analyst and data science interviews.

Course curriculum

Work through the lessons in order, or jump to the level that matches where you are.

Level 1: Foundations

Write your first queries, build tables, and change data safely.

7 lessons · 69 min read

  1. Lesson 1: What Is SQL? A Beginner's Guide to Databases and QueriesLearn what SQL is, how relational databases organize data in tables, the main SQL commands, and how to run your first queries on a free sample database. 10 min read
  2. Lesson 2: SQL SELECT Basics: WHERE, ORDER BY, LIMIT, and DISTINCTLearn to filter, sort, and limit SQL query results with WHERE, AND, OR, IN, BETWEEN, LIKE, IS NULL, ORDER BY, LIMIT, and DISTINCT, with examples you can run. 10 min read
  3. Lesson 3: SQL Aggregate Functions: COUNT, SUM, AVG, MIN, MAX ExplainedLearn SQL aggregate functions with examples: COUNT, SUM, AVG, MIN, MAX, GROUP BY, HAVING, and NULL handling in PostgreSQL, MySQL, SQL Server, and SQLite. 12 min read
  4. Lesson 4: SQL JOINs Explained: A Beginner's GuideLearn SQL JOINs with clear examples: INNER, LEFT, RIGHT, and FULL JOIN explained for absolute beginners. 7 min read
  5. Lesson 5: Creating Tables in SQL: Data Types and ConstraintsLearn to create tables in SQL: choose data types, add primary keys, foreign keys, UNIQUE, CHECK, NOT NULL, and DEFAULT, and change tables with ALTER TABLE. 10 min read
  6. Lesson 6: SQL INSERT, UPDATE, and DELETE: How to Change Data SafelyLearn to add, change, and remove data with SQL INSERT, UPDATE, and DELETE, plus upserts, transactions, and the safety habits that prevent costly mistakes. 10 min read
  7. Lesson 7: NULL in SQL: IS NULL, COALESCE, NULLIF, and Common TrapsUnderstand NULL in SQL: why = NULL fails, three-valued logic, IS NULL, COALESCE, NULLIF, NULLs in joins and aggregates, and the NOT IN trap, with examples. 10 min read

Level 2: Intermediate Queries

Clean, reshape, and combine data with functions, CASE, subqueries, CTEs, and window functions.

8 lessons · 70 min read

  1. Lesson 8: SQL String Functions: How to Clean and Transform TextLearn the most common SQL string functions with examples: TRIM, UPPER, CONCAT, SUBSTRING, REPLACE, and more in PostgreSQL, MySQL, SQL Server, and SQLite. 14 min read
  2. Lesson 9: SQL Date Functions: How to Work With Dates and TimesLearn SQL date and time functions with examples: current date, extract, add, subtract, group by month, in PostgreSQL, MySQL, SQL Server, and SQLite. 12 min read
  3. Lesson 10: SQL CASE Expressions: If-Then Logic in Your QueriesLearn SQL CASE expressions with examples: label and group values, custom sort orders, conditional counts, CASE in UPDATE, and the mistakes that break them. 9 min read
  4. Lesson 11: Mastering SQL Subqueries: A Beginner-to-Advanced GuideA guide to SQL subqueries: syntax, types, and real examples for cleaner, faster queries. 8 min read
  5. Lesson 12: SQL CTEs Explained: Cleaner Queries with WITH (and Recursion)Learn SQL common table expressions (CTEs): write readable step-by-step queries with WITH, chain several CTEs, and use recursive CTEs for date series and trees. 8 min read
  6. Lesson 13: SQL UNION, INTERSECT, and EXCEPT: Combining Query ResultsLearn SQL set operations: stack results with UNION and UNION ALL, find rows two queries share with INTERSECT, and rows only one has with EXCEPT, with examples. 7 min read
  7. Lesson 14: SQL Window Functions: Running Totals & RankingsLearn SQL window functions for running totals, rankings, and moving averages, with clear beginner examples. 6 min read
  8. Lesson 15: Cleaning Messy Data with Pure SQL: A Beginner's GuideLearn how to clean messy data with pure SQL, from trimming whitespace to fixing duplicates, with no extra tools needed. 6 min read

Level 3: Working with Databases

Design databases, speed up queries, protect your data, and automate with views and procedures.

7 lessons · 54 min read

  1. Lesson 16: Database Design: A Beginner's Guide to Planning It RightLearn database design step by step — requirements, entities, relationships, and normalization — built for beginner web designers. 7 min read
  2. Lesson 17: SQL Indexes Explained: How They Work and When to Use ThemLearn how SQL indexes work, how to read EXPLAIN plans, composite and covering indexes, when an index won't help, and the costs of adding too many. 10 min read
  3. Lesson 18: Why Your SQL Query Is Slow (And How to Fix It)Wondering why your SQL query is slow? Learn the most common causes — missing indexes, SELECT *, bad WHERE clauses — and how to fix them. 6 min read
  4. Lesson 19: SQL Transactions and ACID: COMMIT, ROLLBACK, and LocksLearn how SQL transactions keep data consistent: ACID, COMMIT and ROLLBACK, savepoints, error handling, isolation levels, and locks. 8 min read
  5. Lesson 20: SQL Views: How to Create and Use Virtual TablesLearn SQL views: save complex queries as virtual tables, simplify reports, restrict access to columns, update data through views, and use materialized views. 8 min read
  6. Lesson 21: SQL Stored Procedures, Functions, and Triggers ExplainedLearn SQL stored procedures, user-defined functions, and triggers with examples in PostgreSQL, MySQL, and SQL Server, plus when to keep logic in the database. 9 min read
  7. Lesson 22: SQL Injection: How It Works and How to Prevent ItLearn what SQL injection is, how attackers exploit it, and how to prevent it with parameterized queries and input validation. 6 min read

Level 4: Practice

Test yourself with interview-style questions and practice problems.

1 lesson · 16 min read

  1. Lesson 23: SQL and Data Science Interview Questions: Practice GuidePractice SQL and data science interviews with six real-world questions on one downloadable dataset, with step-by-step answers and common traps. 16 min read

A practice database that works everywhere

The lessons share one small shop database with customers, products, and orders. It runs unchanged on PostgreSQL, MySQL, SQLite, and SQL Server, so you can follow along with the database you already have.

Tables in the database

  • customers 8 rows
  • products 6 rows
  • orders 12 rows
Download the practice database

Load it in one command

terminal
# SQLite
sqlite3 shop.db < shop.sql

# PostgreSQL
psql -d shop -f shop.sql

# MySQL
mysql -u root -p shop < shop.sql

# SQL Server
sqlcmd -S localhost -d shop -i shop.sql

Create an empty database first, then run the command for the one you use. Running the file again resets the sample data.

Who this course is for

  • Complete beginners

    You have never written a query. The first lesson starts with what a database is.

  • Excel and spreadsheet users

    You work with tables every day and want to move from formulas to real queries.

  • Analysts and developers

    You know some SQL and want to fill the gaps in joins, window functions, and performance.

Frequently asked questions

Is the course really free?

Yes. Every lesson is a free article on this site, with no signup or paywall.

Which database should I use?

Any of them. The examples work in PostgreSQL, MySQL, SQLite, and SQL Server, and the lessons point out the few places where the syntax differs. If you want the easiest start, SQLite needs no server.

Do I need to know how to code?

No. SQL reads like English, and the first lessons assume no programming experience.

How long does it take?

The lessons add up to a few hours of reading. Most people learn faster by pausing to run each query, so plan a few weeks at a pace of one or two lessons a day.

Can I take the lessons out of order?

Yes, but Level 1 is worth doing first, because later lessons build on it.

Ready to write your first query?

Start with Lesson 1. It explains what a database is and shows you how to set up the practice database.

Start Lesson 1

Need SQL help for your business?

If you would rather have someone build the reports, queries, or database for you, I can help.

Book a Free Consultation
↑