CodeBlanks Logo Icon CodeBlanks
Free 4 levels SQL

SQL

Learn all levels of SQL from SELECT, JOIN and subqueries to indexing and performance tuning.

The SQL course covers all levels from basic queries to advanced optimization and distributed databases. MySQL and PostgreSQL compatible ANSI SQL examples with lessons, projects and challenges.

  • 356 lessons
  • 26 h 16 min
  • 8 projects

No account needed, you can start right away. To save your progress, create a free account

Levels

The SQL course goes from zero to expert in four levels. Start at any level you like.
Not sure of your level? Take the placement test
Beginner

Learn SQL fundamentals: SELECT, WHERE, ORDER BY, LIMIT, data types, INSERT, UPDATE, DELETE and simple JOIN.

  • SELECT basics
  • WHERE filtering
  • Ordering and limit
  • Data types
115 lessons · 8 h 19 min See lessons →
Intermediate

Learn INNER/LEFT/RIGHT/FULL JOIN, GROUP BY, HAVING, aggregate functions, subqueries, VIEW and INDEX basics.

  • INNER JOIN in depth
  • LEFT and RIGHT JOIN
  • FULL and CROSS JOIN
  • GROUP BY
115 lessons · 8 h 19 min See lessons →
Advanced

Learn CTE, recursive CTE, window functions, pivot, materialized views, stored procedures, functions, triggers, transaction isolation and query optimization.

  • CTE
  • Recursive CTE
  • Window functions
  • Pivot and unpivot
81 lessons · 5 h 49 min See lessons →
Expert

Learn database design, index tuning, query optimizer internals, replication, sharding and security.

  • Database design
  • Index tuning
  • Query optimizer
  • Replication and sharding
45 lessons · 3 h 49 min See lessons →

Projects you will build

At every level you combine what you learned into a real page.

How does it work?

Short explanation

Each lesson explains one concept in a few short cards; no long videos or walls of text.

Try it right away

Multiple choice, fill-in-the-blank and matching exercises lock in what you just learned.

Write it yourself

You write real code in the in-browser editor; it is checked instantly and you see the result live.

Curriculum

62 groups · 356 lessons · 26 h 16 min

Learn SQL fundamentals: SELECT, WHERE, ORDER BY, LIMIT, data types, INSERT, UPDATE, DELETE and simple JOIN.

1
SELECT basics
6 lessons · 25 min
  1. 1 What is SELECT? Learn that SELECT pulls data from a table. 4 min
  2. 2 Selecting all columns Learn to fetch every column with SELECT *. 4 min
  3. 3 Selecting specific columns Learn to fetch only the columns you want, separated by commas. 4 min
  4. 4 Column aliases with AS Learn to give columns short names with AS. 4 min
  5. 5 Literal values Learn to use constants and calculations inside SELECT. 4 min
  6. 6 Summary - SELECT basics Combine column selection, aliases and literals to write a query. 5 min
2
WHERE filtering
6 lessons · 25 min
  1. 1 What is WHERE? Learn to filter rows by a condition with WHERE. 4 min
  2. 2 Comparison operators Learn =, <>, <, >, <=, >= operators. 4 min
  3. 3 AND and OR Combine multiple conditions with AND and OR. 4 min
  4. 4 IN and BETWEEN Filter with a list using IN and a range using BETWEEN. 4 min
  5. 5 Pattern matching with LIKE Search text with LIKE and the %, _ wildcards. 4 min
  6. 6 Summary - WHERE filtering Combine comparison, logical and pattern operators to filter rows. 5 min
3
Ordering and limit
6 lessons · 25 min
  1. 1 ORDER BY Sort rows by a column with ORDER BY. 4 min
  2. 2 ASC and DESC Learn ascending and descending ordering. 4 min
  3. 3 Multi-column ordering Sort by multiple columns. 4 min
  4. 4 LIMIT Limit the number of rows returned. 4 min
  5. 5 OFFSET Skip rows and paginate with OFFSET. 4 min
  6. 6 Summary - Ordering and limit Combine ORDER BY, LIMIT and OFFSET to write a paged query. 5 min
4
Project: CRUD appProject
5 lessons · 25 min
  1. 1 Project design Set up the table structure of the CRUD app and write skeleton queries. 5 min
  2. 2 Reading data Write the query to list records with SELECT. 5 min
  3. 3 Inserting data Write the query to add a new record with INSERT. 5 min
  4. 4 Updating data Write the query to update a record with UPDATE. 5 min
  5. 5 Deleting data Write the query to delete a record with DELETE. 5 min
5
Data types
6 lessons · 25 min
  1. 1 Integer types Learn INT, SMALLINT, BIGINT integer types. 4 min
  2. 2 Decimal types Learn DECIMAL, NUMERIC, FLOAT decimal types. 4 min
  3. 3 CHAR and VARCHAR Learn fixed and variable length text types. 4 min
  4. 4 DATE and TIME Learn date and time types. 4 min
  5. 5 BOOLEAN Learn the true/false logical type. 4 min
  6. 6 Summary - Data types Combine columns of different types in one table. 5 min
6
Operators
6 lessons · 25 min
  1. 1 Arithmetic operators Learn +, -, *, /, % arithmetic operators. 4 min
  2. 2 Comparison operators Learn =, <>, !=, <, >, <=, >= comparisons. 4 min
  3. 3 Logical operators Learn AND, OR, NOT logical operators. 4 min
  4. 4 IS NULL Test NULL values with IS NULL and IS NOT NULL. 4 min
  5. 5 String concatenation Join strings with ||. 4 min
  6. 6 Summary - Operators Combine arithmetic, comparison and logical operators in one query. 5 min
7
String functions
6 lessons · 25 min
  1. 1 UPPER and LOWER Convert text to upper or lower case. 4 min
  2. 2 LENGTH Find the length of text. 4 min
  3. 3 SUBSTRING Slice a part of a string. 4 min
  4. 4 TRIM Trim leading and trailing spaces. 4 min
  5. 5 CONCAT Join strings with CONCAT. 4 min
  6. 6 Summary - String functions Combine UPPER, SUBSTRING and CONCAT to format names. 5 min
8
Project: Shopping cartProject
5 lessons · 25 min
  1. 1 Cart design Set up the shopping cart tables and write skeleton queries. 5 min
  2. 2 Listing products Write the query to list products by price and stock. 5 min
  3. 3 Adding to cart Write the INSERT query to add a product to the cart. 5 min
  4. 4 Calculating total Write the query that computes the cart total. 5 min
  5. 5 Removing from cart Write the DELETE query to remove an item from the cart. 5 min
9
Number functions
6 lessons · 25 min
  1. 1 ROUND Round numbers to a given number of decimals. 4 min
  2. 2 CEIL and FLOOR Round numbers up and down. 4 min
  3. 3 ABS Take the absolute value of a number. 4 min
  4. 4 POWER and SQRT Take powers and square roots. 4 min
  5. 5 MOD Get the remainder of division with MOD. 4 min
  6. 6 Summary - Number functions Combine ROUND, ABS and MOD to do calculations. 5 min
10
Date functions
6 lessons · 25 min
  1. 1 CURRENT_DATE and NOW Get today's date and current time. 4 min
  2. 2 EXTRACT Pull year, month, day out of a date. 4 min
  3. 3 Date arithmetic Add and subtract days, months from a date. 4 min
  4. 4 DATEDIFF Find the difference between two dates. 4 min
  5. 5 Date formatting Display dates in different formats. 4 min
  6. 6 Summary - Date functions Compute age and durations with EXTRACT and DATEDIFF. 5 min
11
NULL handling
6 lessons · 25 min
  1. 1 What is NULL? Learn that NULL represents an unknown value. 4 min
  2. 2 IS NULL Find rows with NULL using IS NULL. 4 min
  3. 3 COALESCE Provide a default value for NULL with COALESCE. 4 min
  4. 4 NULLIF Prevent division by zero with NULLIF. 4 min
  5. 5 Three-valued logic Learn how NULL behaves with AND, OR and comparisons. 4 min
  6. 6 Summary - NULL handling Write NULL-safe queries with COALESCE and NULLIF. 5 min
12
DISTINCT
6 lessons · 25 min
  1. 1 What is DISTINCT? Remove duplicate rows with DISTINCT. 4 min
  2. 2 DISTINCT on one column List unique values of a single column. 4 min
  3. 3 Multi-column DISTINCT Use DISTINCT across multiple columns. 4 min
  4. 4 DISTINCT with aggregates Count unique values with COUNT(DISTINCT ...). 4 min
  5. 5 DISTINCT vs GROUP BY Learn the difference between DISTINCT and GROUP BY. 4 min
  6. 6 Summary - DISTINCT Write a report query with DISTINCT and COUNT(DISTINCT). 5 min
13
INSERT
6 lessons · 25 min
  1. 1 INSERT basics Add a new row with INSERT INTO. 4 min
  2. 2 Inserting into specific columns Insert values into only some columns. 4 min
  3. 3 Multiple rows Insert many rows in a single INSERT. 4 min
  4. 4 INSERT with SELECT Copy data from another table. 4 min
  5. 5 DEFAULT values Use the DEFAULT keyword in INSERT. 4 min
  6. 6 Summary - INSERT Transfer data with single and multi-row INSERT. 5 min
14
UPDATE
6 lessons · 25 min
  1. 1 UPDATE basics Update rows with UPDATE. 4 min
  2. 2 Conditional UPDATE Make UPDATE conditional with WHERE. 4 min
  3. 3 Multi-column UPDATE Update several columns in one UPDATE. 4 min
  4. 4 Calculated updates Update based on the current value. 4 min
  5. 5 UPDATE pitfalls Learn the danger of UPDATE without WHERE. 4 min
  6. 6 Summary - UPDATE Combine WHERE and calculated values for safe updates. 5 min
15
DELETE
6 lessons · 25 min
  1. 1 DELETE basics Delete rows with DELETE. 4 min
  2. 2 Conditional DELETE Make DELETE conditional with WHERE. 4 min
  3. 3 DELETE vs TRUNCATE Learn the difference between DELETE and TRUNCATE. 4 min
  4. 4 Emptying a table Safely remove all rows. 4 min
  5. 5 Safe deletion Learn ways to avoid accidental deletion. 4 min
  6. 6 Summary - DELETE Combine WHERE and safety steps to delete safely. 5 min
16
CREATE TABLE
6 lessons · 25 min
  1. 1 CREATE TABLE basics Create a new table. 4 min
  2. 2 Column definitions Learn to give a column name and type. 4 min
  3. 3 NOT NULL Mark required columns with NOT NULL. 4 min
  4. 4 DEFAULT Give columns a default value. 4 min
  5. 5 PRIMARY KEY Define a primary key. 4 min
  6. 6 Summary - CREATE TABLE Combine column types, NOT NULL and PRIMARY KEY to build a table. 5 min
17
Constraints
6 lessons · 25 min
  1. 1 UNIQUE constraint Force unique values with UNIQUE. 4 min
  2. 2 CHECK constraint Add a column rule with CHECK. 4 min
  3. 3 FOREIGN KEY Relate two tables with FOREIGN KEY. 4 min
  4. 4 CASCADE Learn how a child table reacts when the parent changes. 4 min
  5. 5 Constraint management Add and drop constraints. 4 min
  6. 6 Summary - Constraints Combine UNIQUE, CHECK and FOREIGN KEY to design a table. 5 min
18
Simple JOIN
6 lessons · 25 min
  1. 1 What is JOIN? Combine two tables into one result set. 4 min
  2. 2 INNER JOIN Learn the most common JOIN type. 4 min
  3. 3 The ON clause Choose which column to match on. 4 min
  4. 4 Table aliases Give a table a short name in FROM and JOIN. 4 min
  5. 5 Multi-table JOIN Join three or more tables in one query. 4 min
  6. 6 Summary - Simple JOIN Write a two-table report with INNER JOIN, ON and aliases. 5 min
19
Project: Inventory systemProject
5 lessons · 25 min
  1. 1 Inventory design Set up product and category tables and write skeleton queries. 5 min
  2. 2 Product table Write queries to list and filter products. 5 min
  3. 3 Stock movements Write INSERT queries to add new stock. 5 min
  4. 4 Stock report Write the UPDATE query that recomputes stock level. 5 min
  5. 5 Low stock alert Write queries that list low stock and clean up records. 5 min
20
Beginner finalFinal
4 lessons · 24 min
  1. 1 Customer query Write a filtered and ordered query on the customer table. 6 min
  2. 2 Order report Insert, update and delete rows on the order table. 6 min
  3. 3 Data update Write a calculated UPDATE based on existing data. 6 min
  4. 4 Table redesign Rebuild a table with DROP and CREATE. 6 min

Learn INNER/LEFT/RIGHT/FULL JOIN, GROUP BY, HAVING, aggregate functions, subqueries, VIEW and INDEX basics.

1
INNER JOIN in depth
6 lessons · 25 min
  1. 1 INNER JOIN logic Learn that INNER JOIN returns only matching rows. 4 min
  2. 2 Choosing the join column Learn the difference between USING and ON. 4 min
  3. 3 Three-table INNER JOIN Chain JOINs across three tables. 4 min
  4. 4 Self JOIN Join a table to itself. 4 min
  5. 5 Filtering joins Use WHERE together with JOIN. 4 min
  6. 6 Summary - INNER JOIN Write an internal report with self JOIN and chained JOINs. 5 min
2
LEFT and RIGHT JOIN
6 lessons · 25 min
  1. 1 LEFT JOIN Keep all rows from the left table. 4 min
  2. 2 RIGHT JOIN Keep all rows from the right table. 4 min
  3. 3 Unmatched rows Find rows in one table but not the other. 4 min
  4. 4 JOINs with NULL See NULL on the unmatched side. 4 min
  5. 5 LEFT vs RIGHT Choose the right outer join for the task. 4 min
  6. 6 Summary - LEFT and RIGHT JOIN Write a missing-record report with LEFT JOIN. 5 min
3
FULL and CROSS JOIN
6 lessons · 25 min
  1. 1 FULL OUTER JOIN Keep all rows from both tables. 4 min
  2. 2 CROSS JOIN Take the cartesian product of two tables. 4 min
  3. 3 When to CROSS JOIN Learn suitable use cases for CROSS JOIN. 4 min
  4. 4 Comma JOIN Learn the comma form of JOIN. 4 min
  5. 5 Choosing a JOIN type Pick the right JOIN for each scenario. 4 min
  6. 6 Summary - FULL and CROSS JOIN Write a missing supplier and customer report with FULL JOIN. 5 min
4
Project: Library databaseProject
5 lessons · 25 min
  1. 1 Library design Set up book, member and loan tables and write skeleton queries. 5 min
  2. 2 Books and authors Write the INNER JOIN query for books and authors. 5 min
  3. 3 List loans with LEFT JOIN List every member and their loans with LEFT JOIN. 5 min
  4. 4 Find overdue loans Find overdue loans with LEFT JOIN and WHERE. 5 min
  5. 5 Member summary Write a mixed report with FULL JOIN. 5 min
5
GROUP BY
6 lessons · 25 min
  1. 1 What is GROUP BY? Group rows by a column. 4 min
  2. 2 Single-column grouping Group by one column. 4 min
  3. 3 Multi-column grouping Group by multiple columns. 4 min
  4. 4 GROUP BY with aggregates Use COUNT, SUM and friends with groups. 4 min
  5. 5 Ordering grouped results Sort grouped results. 4 min
  6. 6 Summary - GROUP BY Write a category report with multi-column GROUP BY. 5 min
6
HAVING
6 lessons · 25 min
  1. 1 What is HAVING? Filter groups with HAVING. 4 min
  2. 2 HAVING vs WHERE Learn the difference between HAVING and WHERE. 4 min
  3. 3 HAVING with aggregates Filter groups by COUNT or SUM. 4 min
  4. 4 Multiple conditions Use AND and OR inside HAVING. 4 min
  5. 5 HAVING with aliases Alias an aggregate and use it in HAVING. 4 min
  6. 6 Summary - HAVING Find the top-selling category with GROUP BY and HAVING. 5 min
7
Aggregate functions
6 lessons · 25 min
  1. 1 COUNT Count rows with COUNT. 4 min
  2. 2 SUM Sum numeric values with SUM. 4 min
  3. 3 AVG Compute the average. 4 min
  4. 4 MIN and MAX Get the smallest and largest values. 4 min
  5. 5 NULL and aggregates See how NULL affects aggregates. 4 min
  6. 6 Summary - Aggregates Write a summary report with COUNT, SUM, AVG, MIN and MAX. 5 min
8
Project: Sales reportProject
5 lessons · 25 min
  1. 1 Sales design Set up the sales tables and write skeleton queries. 5 min
  2. 2 Daily revenue Write the GROUP BY query for daily revenue. 5 min
  3. 3 Best sellers Find the best-selling product with HAVING. 5 min
  4. 4 Customer segments Write a customer segment report with AVG. 5 min
  5. 5 Low performers Find low-performing categories with HAVING. 5 min
9
Subquery
6 lessons · 25 min
  1. 1 What is a subquery? Run a query inside another query. 4 min
  2. 2 Scalar subquery Use a single-value subquery. 4 min
  3. 3 Subquery with IN Use a subquery inside IN. 4 min
  4. 4 ANY and ALL Compare against a subquery with ANY and ALL. 4 min
  5. 5 Correlated subquery Use a subquery that references the outer query. 4 min
  6. 6 Summary - Subquery Find rows above the average with IN and scalar subqueries. 5 min
10
EXISTS
6 lessons · 25 min
  1. 1 What is EXISTS? Check whether a subquery returns any row. 4 min
  2. 2 NOT EXISTS Find rows that fail a condition. 4 min
  3. 3 EXISTS vs IN Learn the difference between EXISTS and IN. 4 min
  4. 4 EXISTS performance Learn when EXISTS is faster. 4 min
  5. 5 Multiple EXISTS Combine several EXISTS with AND/OR. 4 min
  6. 6 Summary - EXISTS Find customers with no orders using NOT EXISTS. 5 min
11
UNION and INTERSECT
6 lessons · 25 min
  1. 1 UNION Combine the results of two queries. 4 min
  2. 2 UNION ALL Keep duplicates when combining. 4 min
  3. 3 INTERSECT Take rows common to two queries. 4 min
  4. 4 EXCEPT Take rows in one query but not the other. 4 min
  5. 5 Set rules Learn column count and type rules for set queries. 4 min
  6. 6 Summary - UNION and INTERSECT Find rows in either or only one list with UNION and EXCEPT. 5 min
12
CASE
6 lessons · 25 min
  1. 1 What is CASE? Use CASE for conditional output. 4 min
  2. 2 Searched CASE Write the searched form of CASE. 4 min
  3. 3 Simple CASE Learn the simple CASE form. 4 min
  4. 4 The ELSE branch Provide a default with ELSE. 4 min
  5. 5 CASE with aggregates Use CASE inside an aggregate. 4 min
  6. 6 Summary - CASE Write a conditional total report with CASE and SUM. 5 min
13
VIEW
6 lessons · 25 min
  1. 1 What is a VIEW? Create a virtual table. 4 min
  2. 2 CREATE VIEW Save a query as a view. 4 min
  3. 3 Querying a VIEW Query a view like a table. 4 min
  4. 4 DROP VIEW Drop a view. 4 min
  5. 5 Updatable VIEWs Insert, update and delete through some views. 4 min
  6. 6 Summary - VIEW Store a complex query as a view and reuse it. 5 min
14
INDEX basics
6 lessons · 25 min
  1. 1 What is an INDEX? Learn that an index speeds up search. 4 min
  2. 2 CREATE INDEX Create a single-column index. 4 min
  3. 3 Composite INDEX Create a multi-column index. 4 min
  4. 4 DROP INDEX Remove an index. 4 min
  5. 5 When to index Choose which columns to index. 4 min
  6. 6 Summary - INDEX Speed up a search query with CREATE INDEX. 5 min
15
Project: Blog databaseProject
5 lessons · 25 min
  1. 1 Blog design Set up author, post and tag tables and write skeleton queries. 5 min
  2. 2 Post list Write the VIEW that lists recent posts. 5 min
  3. 3 Tag search Find posts with a tag using EXISTS. 5 min
  4. 4 Author stats Write an author stats report with CASE and SUM. 5 min
  5. 5 Search index Speed up search with CREATE INDEX. 5 min
16
Normalization
6 lessons · 25 min
  1. 1 What is normalization? Learn the idea of organising data without repeats. 4 min
  2. 2 First normal form Learn first normal form (1NF). 4 min
  3. 3 Second normal form Learn second normal form (2NF). 4 min
  4. 4 Third normal form Learn third normal form (3NF). 4 min
  5. 5 BCNF Learn Boyce-Codd normal form. 4 min
  6. 6 Summary - Normalization Bring a denormalised table up to 3NF. 5 min
17
Data integrity
6 lessons · 25 min
  1. 1 What is integrity? Learn the concept of data consistency. 4 min
  2. 2 Entity integrity Learn entity integrity with PRIMARY KEY. 4 min
  3. 3 Referential integrity Learn referential integrity with FOREIGN KEY. 4 min
  4. 4 Domain integrity Learn domain integrity with column rules. 4 min
  5. 5 Integrity with triggers Add extra integrity rules with triggers. 4 min
  6. 6 Summary - Data integrity Build a consistent table with PRIMARY KEY, FOREIGN KEY and CHECK. 5 min
18
Transaction basics
6 lessons · 25 min
  1. 1 What is a transaction? Treat several operations as one unit. 4 min
  2. 2 BEGIN and COMMIT Open and close a transaction. 4 min
  3. 3 ROLLBACK Undo on error with ROLLBACK. 4 min
  4. 4 SAVEPOINT Do a partial rollback. 4 min
  5. 5 ACID Learn the ACID principles. 4 min
  6. 6 Summary - Transaction Write a money transfer with BEGIN, COMMIT and ROLLBACK. 5 min
19
ALTER and DROP
6 lessons · 25 min
  1. 1 ALTER TABLE Change an existing table. 4 min
  2. 2 Adding a column Add a column with ADD COLUMN. 4 min
  3. 3 Dropping a column Remove a column with DROP COLUMN. 4 min
  4. 4 Changing a column type Change a column type with ALTER COLUMN. 4 min
  5. 5 DROP TABLE Delete a table. 4 min
  6. 6 Summary - ALTER and DROP Safely update a table with ALTER TABLE. 5 min
20
Intermediate finalFinal
4 lessons · 24 min
  1. 1 Multi-JOIN report Write a report joining three tables. 6 min
  2. 2 Aggregate analysis Analyse data with GROUP BY, HAVING and CASE. 6 min
  3. 3 Subquery challenge Write a complex condition with a correlated subquery. 6 min
  4. 4 Transaction scenario Write a safe transfer with a transaction. 6 min

Learn CTE, recursive CTE, window functions, pivot, materialized views, stored procedures, functions, triggers, transaction isolation and query optimization.

1
CTE
6 lessons · 25 min
  1. 1 What is a CTE? Write a named subquery with WITH. 4 min
  2. 2 Using WITH Define a CTE with WITH. 4 min
  3. 3 Multiple CTEs Use several CTEs in one query. 4 min
  4. 4 CTE vs subquery Compare CTE and subquery. 4 min
  5. 5 CTE with JOIN Use a CTE inside a JOIN. 4 min
  6. 6 Summary - CTE Write a multi-step report with multiple CTEs. 5 min
2
Recursive CTE
6 lessons · 25 min
  1. 1 What is a recursive CTE? Learn the idea of a self-calling CTE. 4 min
  2. 2 Anchor and recursive parts Learn the two parts joined by UNION ALL. 4 min
  3. 3 Walk a hierarchy Use a recursive CTE to walk a parent-child relationship. 4 min
  4. 4 Tracking depth Compute each row's depth level. 4 min
  5. 5 Stopping recursion Learn when a recursive CTE stops. 4 min
  6. 6 Summary - Recursive CTE Write a company org-chart report with a recursive CTE. 5 min
3
Window functions
6 lessons · 25 min
  1. 1 What is a window function? Compute per row with OVER. 4 min
  2. 2 ROW_NUMBER Number each row. 4 min
  3. 3 RANK and DENSE_RANK Learn the ranking functions. 4 min
  4. 4 LAG and LEAD Reach the previous and next row. 4 min
  5. 5 PARTITION BY Compute windows inside groups. 4 min
  6. 6 Summary - Window functions Write a month-over-month report with ROW_NUMBER and LAG. 5 min
4
Project: Analytics reportProject
5 lessons · 25 min
  1. 1 Analytics design Set up event and user tables and write skeleton queries. 5 min
  2. 2 CTE summary Compute daily active users with a CTE. 5 min
  3. 3 Top users with ROW_NUMBER Find top users with ROW_NUMBER. 5 min
  4. 4 Growth with LAG Compute user growth with LAG. 5 min
  5. 5 Final report Write a hierarchy report with a recursive CTE. 5 min
5
Pivot and unpivot
6 lessons · 25 min
  1. 1 What is pivot? Turn rows into columns. 4 min
  2. 2 Pivot with CASE Pivot using CASE and aggregates. 4 min
  3. 3 FILTER clause Learn the FILTER keyword. 4 min
  4. 4 Unpivot Turn columns into rows. 4 min
  5. 5 Dynamic pivot Pivot when the column count changes. 4 min
  6. 6 Summary - Pivot Write a monthly sales pivot with CASE. 5 min
6
Materialized view
6 lessons · 25 min
  1. 1 What is a materialized view? Learn the view that stores its result. 4 min
  2. 2 CREATE Create a materialized view. 4 min
  3. 3 REFRESH Refresh a materialized view. 4 min
  4. 4 View vs materialized view Compare the two view types. 4 min
  5. 5 Index on materialized views Add an index to a materialized view. 4 min
  6. 6 Summary - Materialized view Speed up a heavy report with a materialized view. 5 min
7
Stored procedure
6 lessons · 25 min
  1. 1 What is a procedure? Learn the server-side stored routine. 4 min
  2. 2 CREATE PROCEDURE Create a procedure. 4 min
  3. 3 Parameters Learn IN and OUT parameters. 4 min
  4. 4 CALL Invoke a procedure. 4 min
  5. 5 Control flow Use IF and LOOP inside a procedure. 4 min
  6. 6 Summary - Stored procedure Write a balance update with CREATE PROCEDURE. 5 min
8
Function
6 lessons · 25 min
  1. 1 What is a function? Learn routines that return a scalar value. 4 min
  2. 2 CREATE FUNCTION Define a function. 4 min
  3. 3 RETURN Return a value. 4 min
  4. 4 Calling a function Call a function inside SELECT. 4 min
  5. 5 Function vs procedure Compare the two routine types. 4 min
  6. 6 Summary - Function Compute tax with CREATE FUNCTION. 5 min
9
Trigger
6 lessons · 25 min
  1. 1 What is a trigger? Learn routines that fire on an event. 4 min
  2. 2 BEFORE and AFTER Learn the timing difference. 4 min
  3. 3 INSERT trigger Fire after an INSERT. 4 min
  4. 4 UPDATE trigger Fire after an UPDATE. 4 min
  5. 5 Write an audit trigger Log changes with an audit trigger. 4 min
  6. 6 Summary - Trigger Update stock with an AFTER INSERT trigger. 5 min
10
Transaction isolation
6 lessons · 25 min
  1. 1 What is isolation? Learn how transactions see each other. 4 min
  2. 2 READ UNCOMMITTED Learn the lowest level and dirty reads. 4 min
  3. 3 READ COMMITTED Learn the middle level and non-repeatable reads. 4 min
  4. 4 REPEATABLE READ Learn repeatable reads. 4 min
  5. 5 SERIALIZABLE Learn the highest level. 4 min
  6. 6 Summary - Isolation Pick the right level with SET TRANSACTION. 5 min
11
Locking
6 lessons · 25 min
  1. 1 What is a lock? Queue concurrent access. 4 min
  2. 2 Shared and exclusive locks Learn shared vs exclusive locks. 4 min
  3. 3 Deadlock Learn the mutual-wait gridlock. 4 min
  4. 4 SELECT FOR UPDATE Lock rows for update. 4 min
  5. 5 Lock timeout Learn the lock wait timeout. 4 min
  6. 6 Summary - Locking Update a balance safely with SELECT FOR UPDATE. 5 min
12
Query optimization
6 lessons · 25 min
  1. 1 What is EXPLAIN? See the query plan. 4 min
  2. 2 Seq scan vs index scan Learn table scan vs index scan. 4 min
  3. 3 Cost Read the cost of a plan. 4 min
  4. 4 Sargable Write conditions that use indexes. 4 min
  5. 5 N+1 problem Learn the N+1 query trap. 4 min
  6. 6 Summary - Optimization Improve a slow query with EXPLAIN. 5 min
13
Partitioning
6 lessons · 25 min
  1. 1 What is partitioning? Split a large table into pieces. 4 min
  2. 2 Range partition Partition by a value range. 4 min
  3. 3 List partition Partition by a list of values. 4 min
  4. 4 Hash partition Partition by a hash. 4 min
  5. 5 Partition pruning Scan only the relevant partition. 4 min
  6. 6 Summary - Partitioning Build a monthly event table with range partitioning. 5 min
14
Advanced finalFinal
4 lessons · 24 min
  1. 1 Hierarchy report Write an org-chart report with a recursive CTE. 6 min
  2. 2 Window analysis Do ranking and delta analysis with window functions. 6 min
  3. 3 Procedure and trigger Write a balance procedure and an audit trigger. 6 min
  4. 4 Optimization Read a plan with EXPLAIN and improve the query. 6 min

Learn database design, index tuning, query optimizer internals, replication, sharding and security.

1
Database design
6 lessons · 30 min
  1. 1 ER model Learn the Entity-Relationship model. 5 min
  2. 2 Cardinality Learn one-to-one, one-to-many and many-to-many. 5 min
  3. 3 Surrogate keys Learn auto-incrementing keys. 5 min
  4. 4 Natural keys Learn natural keys. 5 min
  5. 5 Denormalization Learn the deliberate repeat scenario. 5 min
  6. 6 Summary - Design Move from an ER model to table design. 5 min
2
Index tuning
6 lessons · 30 min
  1. 1 B-tree structure Learn the B-tree index structure. 5 min
  2. 2 Covering index Cover all columns with one index. 5 min
  3. 3 Partial index Index a subset of rows. 5 min
  4. 4 Index selectivity Learn selectivity and cardinality. 5 min
  5. 5 Index maintenance Learn rebuild and analyze. 5 min
  6. 6 Summary - Index tuning Speed up a query with a covering index. 5 min
3
Query optimizer
6 lessons · 30 min
  1. 1 What is an optimizer? Learn the role of the query optimizer. 5 min
  2. 2 Statistics Learn statistics and histograms. 5 min
  3. 3 Cost model Learn cost-based planning. 5 min
  4. 4 Join strategies Learn hash, merge and nested loop joins. 5 min
  5. 5 Plan cache Learn the plan cache. 5 min
  6. 6 Summary - Optimizer Refresh statistics with ANALYZE. 5 min
4
Project: Performance tuningProject
5 lessons · 25 min
  1. 1 Scenario design Set up the slow-report scenario and write skeleton queries. 5 min
  2. 2 Reading plans Inspect the slow plan with EXPLAIN. 5 min
  3. 3 Adding indexes Speed up the query with a covering index. 5 min
  4. 4 Rewriting queries Make the query sargable. 5 min
  5. 5 Comparing results Compare before and after plans. 5 min
5
Replication and sharding
6 lessons · 30 min
  1. 1 What is replication? Copy data to another server. 5 min
  2. 2 Master-slave Learn the primary and replica structure. 5 min
  3. 3 Sync vs async Learn synchronous and asynchronous replication. 5 min
  4. 4 What is sharding? Split data across servers. 5 min
  5. 5 Shard key Choose a shard key. 5 min
  6. 6 Summary - Replication and sharding Shard a users table by shard key. 5 min
6
Distributed and big data
6 lessons · 30 min
  1. 1 Distributed queries Run queries across multiple servers. 5 min
  2. 2 MPP Learn massively parallel processing. 5 min
  3. 3 Columnar storage Learn column-oriented storage. 5 min
  4. 4 SQL on Hadoop Run SQL over big data. 5 min
  5. 5 SQL vs NoSQL Compare SQL and NoSQL. 5 min
  6. 6 Summary - Distributed and big data Speed up an analytical query with columnar storage. 5 min
7
Security and backup
6 lessons · 30 min
  1. 1 SQL injection Learn injection attacks and prevention. 5 min
  2. 2 Parameterised queries Use prepared statements. 5 min
  3. 3 Authorisation Manage access with GRANT and REVOKE. 5 min
  4. 4 Backup Take full and incremental backups. 5 min
  5. 5 Recovery Learn point-in-time recovery. 5 min
  6. 6 Summary - Security and backup Build a secure setup with GRANT and prepared statements. 5 min
8
Expert finalFinal
4 lessons · 24 min
  1. 1 Design challenge Turn an ER model into tables and add indexes. 6 min
  2. 2 Optimization challenge Improve a slow query by reading its plan. 6 min
  3. 3 Security challenge Secure the app with parameterised queries and GRANT. 6 min
  4. 4 Backup challenge Write a backup and recovery scenario. 6 min

Lessons are free, an account keeps your progress

You do not have to sign up. If you do, you continue where you left off and never lose your work.

  • Progress saved on every device
  • Earn XP and badges
  • Keep your daily streak
  • Get a certificate when you finish
create a free account

Frequently asked questions

Are the SQL lessons free?

Yes. All 356 lessons of the SQL course are free and you can start without an account.

Do I need any prior knowledge?

No. The beginner level starts from zero; a browser is all you need. If you already know the basics, start at a higher level.

How long does the course take?

Lessons take 2–8 minutes. The whole course is about 26 hours; with 15–20 minutes a day you can finish in a few months.

Do I get a certificate?

Yes. When you complete the course with a free account, a verifiable certificate is issued in your name.

Will I lose my progress without an account?

Without an account your progress is kept only in your current browser. When you create a free account it is moved to your account.

Next step Git

Learn version control, branching, merging, rebase and team workflows with Git and GitHub.