Free · No signup required

Learn SQL — Interactive Lessons

Bite-sized lessons with live examples, interactive exercises and quizzes. Go from zero to writing real SQL queries — no theory walls, just hands-on practice.

📚 38 lessons📝 Quizzes after every lesson⚡ 100% free🚀 No signup
SQL Fundamentals Track
  Lesson 01
The BIG 6 SQL Clauses

Master SELECT, FROM, WHERE, GROUP BY, HAVING and ORDER BY with an interactive query builder and a 6-question quiz.

5 clausesInteractive builder6-question quiz~15 min
  Lesson 02
Data Types

Master INT, VARCHAR, DECIMAL, DATE, DATETIME and BOOLEAN — when to use each, why phone numbers need VARCHAR, why prices need DECIMAL, and the 4 most common type mistakes. Interactive type explorer and a 6-question quiz.

7 data typesType Explorer4 common mistakes6-question quiz~15 min
  Lesson 02
SELECT DISTINCT

Learn how to remove duplicate rows and retrieve unique values. Side-by-side demos show exactly what DISTINCT changes in the result set.

4 conceptsSide-by-side demos5-question quiz~10 min
  Lesson 03
WHERE Clause

Filter rows with 9 operators (=, !=, >, <, BETWEEN, LIKE, IN, IS NULL, AND/OR), interactive demos and real-world examples.

9 operatorsAND/OR toggle demo6-question quiz~15 min
  Lesson 04
WHERE & IN

Master the IN operator — the clean shortcut for multiple OR conditions. Interactive OR vs IN demos, real-world examples, common mistakes and a 6-question quiz.

5 conceptsOR vs IN live demo6-question quiz~10 min
  Lesson 05
LIKE

Search patterns instead of exact values using % and _ wildcards. Starts-with, ends-with, contains — all covered with interactive demos and a 6-question quiz.

5 concepts% and _ wildcards6-question quiz~12 min
Σ   Lesson 06
GROUP BY

Summarize data with COUNT, SUM, AVG, MIN, MAX. Learn clause order, multi-column grouping, HAVING vs WHERE, and the most common beginner mistakes.

5 conceptsCOUNT SUM AVG MIN MAX6-question quiz~15 min
/   Lesson 07
Comments & Aliases

Write self-documenting SQL with -- and /* */ comments. Use AS to give output columns clean, readable names. Real-world examples and a 6-question quiz.

5 concepts-- and /* */ commentsAS alias6-question quiz~10 min
  Lesson 08
Advanced GROUP BY

Go deeper with multi-column grouping, all 6 aggregate functions (including COUNT DISTINCT), NULL handling and real-world examples across e-commerce, school, and movies datasets.

5 conceptsMulti-column groupingCOUNT DISTINCT6-question quiz~15 min
  Lesson 09
HAVING Clause

Filter groups after GROUP BY using aggregate functions. Learn HAVING vs WHERE, clause order, and real-world analytics examples — with an interactive step-by-step demo and a 6-question quiz.

6 conceptsWHERE vs HAVINGStep-by-step demo6-question quiz~12 min
  Lesson 10
ORDER BY

Sort query results ascending or descending, use multiple columns as tie-breakers, and combine with GROUP BY to rank summaries. Interactive demos and a 6-question quiz.

6 conceptsASC & DESCMulti-column sort6-question quiz~10 min
  Lesson 11
LIMIT / TOP / FETCH

Restrict how many rows a query returns. ORDER BY + LIMIT for top-N reports, OFFSET for pagination, plus SQL Server TOP and ANSI FETCH FIRST ROWS ONLY compared side by side.

9 conceptsTop N & OFFSETTOP vs FETCH10-question quiz~20 min
  Lesson 12
SQL JOINs — Complete Beginner Guide

Quick-reference overview of all 6 JOIN types side by side — INNER, LEFT, RIGHT, FULL OUTER, CROSS and SELF — with a cheat sheet you’ll come back to. Each JOIN then gets its own deep-dive lesson next.

📋 Quick overview6 JOIN typesJOIN cheat sheet15-question quiz~30 min
  Lesson 13
SQL INNER JOIN

Optional deep-dive on INNER JOIN specifically (you saw the basics in Lesson 12) — how matching works, joining 3+ tables, 15 real business use cases, a cheat sheet, and 25 interview Q&As. Great for interview prep; skip ahead to Subqueries if you just need the fundamentals.

🔎 Deep diveMulti-table JOINs25 interview Q&As15-question quiz~30 min
  Lesson 14
SQL LEFT JOIN

Optional deep-dive on LEFT JOIN specifically — keep every row from the left table, understand NULLs, find missing records, 15 business use cases, and 25 interview Q&As. Great for interview prep; skip ahead to Subqueries if you just need the fundamentals.

🔎 Deep diveFind missing records25 interview Q&As15-question quiz~30 min
  Lesson 15
SQL RIGHT JOIN

Optional deep-dive on RIGHT JOIN specifically — keep every row from the right table, RIGHT JOIN vs LEFT/INNER/FULL OUTER JOIN, 20 business use cases, and 30 interview Q&As. Great for interview prep; skip ahead to Subqueries if you just need the fundamentals.

🔎 Deep diveRight-table preserved30 interview Q&As15-question quiz~30 min
  Lesson 16
SQL FULL OUTER JOIN

Optional deep-dive on FULL OUTER JOIN specifically — combine LEFT and RIGHT JOIN behavior, reconcile data with NULLs on both sides, the MySQL workaround, 20 business use cases, and 30 interview Q&As. Great for interview prep; skip ahead to Subqueries if you just need the fundamentals.

🔎 Deep diveBoth sides preserved30 interview Q&As15-question quiz~30 min
  Lesson 17
SQL SELF JOIN

Optional deep-dive on SELF JOIN specifically — join a table to itself with aliases, model employee-manager hierarchies and organizational charts, 20 business use cases, and 30 interview Q&As. Great for interview prep; skip ahead to Subqueries if you just need the fundamentals.

🔎 Deep diveEmployee-manager hierarchies30 interview Q&As15-question quiz~30 min
  Lesson 18
SQL CROSS JOIN

Optional deep-dive on CROSS JOIN specifically — generate every possible combination of rows with the Cartesian Product, avoid accidental CROSS JOINs, 20 business use cases, and 30 interview Q&As. Great for interview prep; head to Subqueries next if you just need the fundamentals.

🔎 Deep diveCartesian Product30 interview Q&As15-question quiz~30 min
  Lesson 19
SQL Subqueries

The complete beginner-to-advanced guide to Subqueries — single-row and multiple-row subqueries, subqueries in WHERE/SELECT/FROM, nested subqueries, Subquery vs JOIN, 20 business use cases, and a 15-question quiz.

Query inside a query20 business scenarios35 interview Q&As15-question quiz~35 min
  Lesson 20
SQL Correlated Subqueries

The complete beginner-to-advanced guide to Correlated Subqueries — row-by-row execution, EXISTS/NOT EXISTS, Correlated Subquery vs Subquery vs JOIN vs Window Functions, 25 business use cases, and a 20-question quiz.

Depends on outer query25 business scenarios40 interview Q&As20-question quiz~40 min
  Lesson 21
SQL EXISTS

The complete beginner-to-advanced guide to the EXISTS operator — how it checks row existence, SELECT 1 best practice, EXISTS vs IN vs JOIN vs COUNT, 25 business use cases, and a 20-question quiz.

Checks row existence25 business scenarios40 interview Q&As20-question quiz~35 min
  Lesson 22
IN vs EXISTS

The complete beginner-to-advanced guide comparing IN and EXISTS — list membership vs row existence, short-circuit evaluation, NULL-safety, EXISTS vs JOIN, 25 business use cases, and a 20-question quiz.

∈ vs ∃Short-circuit evaluation25 business scenarios40 interview Q&As20-question quiz~45 min
Σ   Lesson 23
SQL Aggregate Functions

The complete beginner-to-advanced guide to COUNT, SUM, AVG, MAX, and MIN — COUNT(*) vs COUNT(column), GROUP BY & HAVING, NULL-handling, 30 business use cases, and a 25-question quiz.

COUNT · SUM · AVG · MAX · MINNULL-handling deep dive30 business scenarios50 interview Q&As25-question quiz~55 min
"   Lesson 24
SQL String Functions

The complete beginner-to-advanced guide to CONCAT, UPPER, LOWER, LENGTH, TRIM, SUBSTRING, and REPLACE — real SQL data cleaning recipes, 30 business use cases, and a 25-question quiz.

CONCAT · UPPER · LOWER · TRIMSUBSTRING & REPLACE30 business scenarios50 interview Q&As25-question quiz~65 min
  Lesson 25
SQL Date Functions

The complete beginner-to-advanced guide to CURRENT_DATE, NOW, YEAR, MONTH, DAY, DATEADD, DATEDIFF, and EXTRACT — age calculation, MoM/YoY analysis, 35 business use cases, and a 29-question quiz.

CURRENT_DATE · NOW · YEAR/MONTH/DAYDATEADD · DATEDIFF · EXTRACT35 business scenarios50 interview Q&As29-question quiz~70 min
  Lesson 26
SQL CASE WHEN

The complete beginner-to-advanced guide to CASE WHEN — simple and multiple conditions, CASE WHEN vs IF ELSE, conditional aggregation, GROUP BY/ORDER BY, NULL handling, nested CASE, 40 business use cases, and a 29-question quiz.

Simple & multiple conditionsConditional aggregation (SUM/COUNT)40 business scenarios54 interview Q&As29-question quiz~60 min
  Lesson 27
SQL COALESCE

The complete beginner-to-advanced guide to COALESCE — returning the first non-NULL value, multi-column fallback chains, calculations, conditional aggregation, LEFT JOINs, COALESCE vs ISNULL/IFNULL/NVL/CASE WHEN, 35 business use cases, and a 30-question quiz.

First non-NULL valueMulti-column fallback chains35 business scenarios50 interview Q&As30-question quiz~55 min
÷   Lesson 28
SQL NULLIF

The complete beginner-to-advanced guide to NULLIF — comparing two values, divide-by-zero prevention, numbers/text/dates, aggregate functions, NULLIF vs COALESCE/CASE WHEN/ISNULL/IFNULL, 35 business use cases, and a 30-question quiz.

Divide-by-zero preventionNULLIF vs COALESCE35 business scenarios50 interview Q&As30-question quiz~55 min
  Lesson 29
SQL Window Functions

The complete beginner-to-advanced guide to Window Functions — OVER, PARTITION BY, ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, running totals, moving averages, window frames, 50 business use cases, and a 41-question quiz.

OVER · PARTITION BY · ORDER BYROW_NUMBER · RANK · LAG · LEAD50 business scenarios75 interview Q&As41-question quiz~90 min
  Lesson 30
SQL CTEs (WITH Clause)

The complete beginner-to-advanced guide to Common Table Expressions — the WITH clause, multiple and chained CTEs, CTE vs Subquery/Temp Table, recursive CTEs for hierarchies and category trees, second-highest salary, 50 business use cases, and a 40-question quiz.

WITH · Multiple · Chained CTEsRecursive CTEs · Org Charts50 business scenarios80 interview Q&As40-question quiz~95 min
  Lesson 31
SQL Views

The complete beginner-to-advanced guide to SQL Views — CREATE VIEW, virtual tables, updatable views, Materialized Views, View vs Table/CTE/Temp Table/Subquery, data security, BI dashboards, 50 business use cases, and a 40-question quiz.

CREATE VIEW · Virtual TablesMaterialized Views50 business scenarios77 interview Q&As40-question quiz~100 min
  Lesson 32
SQL Indexes

The complete beginner-to-advanced guide to SQL Indexes — CREATE INDEX, B-Trees, Clustered vs Non-Clustered, Composite/Covering/Filtered Indexes, EXPLAIN execution plans, 50 business use cases, and a 50-question quiz.

CREATE INDEX · B-TreesClustered vs Non-Clustered50 business scenarios100 interview Q&As50-question quiz~110 min
  Lesson 33
SQL Transactions

The complete beginner-to-advanced guide to SQL Transactions — BEGIN/COMMIT/ROLLBACK, SAVEPOINT, ACID properties, isolation levels, dirty reads, deadlocks, distributed transactions and 2PC, 36 business scenarios, and a 35-question quiz.

ACID propertiesCOMMIT · ROLLBACK · SAVEPOINTIsolation levels & deadlocks36 business scenarios89 interview Q&As35-question quiz~120 min
  Lesson 34
SQL Stored Procedures

The complete beginner-to-advanced guide to SQL Stored Procedures — CREATE PROCEDURE, input/output parameters, CRUD procedures, TRY CATCH error handling, dynamic SQL, Procedure vs Function/View/Trigger, 43 business scenarios, and a 40-question quiz.

CREATE PROCEDUREInput & Output ParametersTRY CATCH · Dynamic SQL43 business scenarios92 interview Q&As40-question quiz~120 min
  Lesson 35
SQL Triggers

The complete beginner-to-advanced guide to SQL Triggers — CREATE TRIGGER, BEFORE/AFTER/INSTEAD OF, OLD and NEW values, audit logging, compliance reporting, Trigger vs Stored Procedure, 45 business scenarios, and a 41-question quiz.

CREATE TRIGGERBEFORE · AFTER · INSTEAD OFAudit Logging & Compliance45 business scenarios98 interview Q&As41-question quiz~130 min
🎤   Lesson 36
SQL Interview Questions & Answers

The complete capstone guide to SQL interview preparation — 350+ questions and answers, 30 query-writing problems, 30 real business scenarios, 30 coding challenges, company-wise patterns, a 30-day prep plan, a full mock interview, and a 40-question quiz.

350+ Q&As & challenges30 query-writing problems30 business scenariosCompany-wise patterns30-day prep plan40-question quiz
  Lesson 37
Operators & Expressions

Arithmetic, comparison, logical, and string operators — all the building blocks for writing conditional SQL.

🔒 Coming soon

Why Learn SQL in 2025?

SQL (Structured Query Language) is the universal language for working with databases. It is used in every industry — from e-commerce and finance to healthcare and data science. According to Stack Overflow's developer survey, SQL consistently ranks among the top three most-used technologies year after year. Whether you are a developer, analyst, data scientist or product manager, SQL is a skill that directly increases your earning potential and career flexibility.

What You Will Learn

Our SQL fundamentals track covers everything a beginner needs to start writing useful queries:

  • The BIG 6 Clauses — SELECT, FROM, WHERE, GROUP BY, HAVING and ORDER BY
  • SELECT DISTINCT — remove duplicates and find unique values
  • WHERE Clause — filter rows with 9 operators and AND/OR logic
  • JOINs — combine data from multiple tables (coming soon)
  • GROUP BY & Aggregates — COUNT, SUM, AVG, MIN, MAX (coming soon)

How the Lessons Work

Each lesson is structured in the same way: a concise explanation with real-life analogies, interactive code examples you can explore in the browser, side-by-side result previews that show exactly what each SQL keyword changes in the output, and a quiz at the end to lock in what you learned.

After finishing a lesson, head to the SQL Playground to practise against our live database, or try one of the SQL Challenges which range from beginner SELECT queries to advanced CTEs. You can also take the SQL Skill Test to benchmark yourself against interview-level questions.

No Setup Required

Everything runs in the browser. No software to install, no database to configure. The playground uses SQLite compiled to WebAssembly, so queries run instantly on your machine without any server round-trip. Every lesson is mobile-friendly and works on any device.

Frequently Asked Questions

Do I need to create an account to access the SQL lessons?

No. Every lesson on SQLabHub is completely free and requires no registration. Just click a lesson and start learning.

What SQL dialect do the lessons cover?

Standard SQL (ANSI SQL) that works in PostgreSQL, MySQL, SQLite, and SQL Server. Dialect-specific differences are noted wherever relevant.

How long does it take to complete all the lessons?

Each lesson takes 10–20 minutes. The full fundamentals track (6 lessons, when complete) takes roughly 2–3 hours at a comfortable pace.

Can I practise what I learn in the lessons?

Yes — the SQL Playground lets you write real queries against a live SQLite database (8 tables, 1,370+ rows). Combine it with the Challenges for guided practice.

Are there quizzes to test my knowledge?

Every lesson ends with an interactive multiple-choice quiz (5–6 questions). Instant feedback and explanations are provided for each answer.

In what order should I study the lessons?

Follow the numbered order: start with The BIG 6, then SELECT DISTINCT, then WHERE. Each lesson builds on the previous one.

Ready to practise what you learned?

Write real SQL queries against our 8-table, 1,370+ row database — no signup needed.

⚡ Open SQL Playground🎯 Browse Challenges