AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started

SQL

The language every backend, data and placement round asks for — SELECT and filtering, NULLs, functions, GROUP BY, joins, subqueries, CTEs, window functions, data changes, schema design, indexes and transactions — in MySQL 8, with every query judged in your browser's next second.

16 modules · 99 lessons · ~27 h · exercises run on MySQL 8 syntax on SQLite 3.49

Syllabus

Nothing is locked. Every module has a PDF.

01

Foundations

you are here
what a relational database is — tables, typed columns, rows without order, primary and foreign keys; SQL as a declarative language and its statement families; MySQL beside PostgreSQL, SQLite and SQL Server; the first SELECT; and the logical order a query's clauses run in.
0/6 · 92 minPDF
02

Selecting and filtering

aliases for columns and tables and where they work; calculated columns with arithmetic, decimal division, DIV, MOD, ROUND and CONCAT; WHERE with comparisons on numbers, text and dates; AND, OR and NOT with precedence and three-valued logic; IN, BETWEEN and LIKE; and DISTINCT with COUNT(DISTINCT).
0/7 · 108 minPDF
03

Sorting and limiting

ORDER BY with ASC and DESC, aliases, expressions and where NULLs sort; several keys, tie-breakers and custom orders; LIMIT and OFFSET with MySQL's comma form, TOP and FETCH FIRST; offset and keyset pagination; top-N queries and the Nth highest value.
0/6 · 96 minPDF
04

NULLs and expressions

NULL as a missing value, UNKNOWN and three-valued logic, IS NULL and MySQL's NULL-safe equality, COALESCE, IFNULL and NULLIF, searched and simple CASE, data types, DIV versus decimal division, implicit conversion and CAST.
0/6 · 97 minPDF
05

Functions

String functions to join, clean, cut and pad text; ROUND, CEIL, FLOOR, DIV and MOD; date types, date parts and DATE_FORMAT; date arithmetic with INTERVAL, DATEDIFF and TIMESTAMPDIFF; and IF, IFNULL, NULLIF, GREATEST and FIELD.
0/6 · 93 minPDF
06

Aggregation

COUNT, SUM, AVG, MIN and MAX and how they treat NULL; GROUP BY on columns and expressions; HAVING versus WHERE; conditional aggregation for counts, pivots and rates; GROUP_CONCAT; and the grouping mistakes — ONLY_FULL_GROUP_BY, the three COUNTs and averages of averages.
0/7 · 104 minPDF
07

Joins

INNER JOIN and row multiplication, LEFT and RIGHT JOIN with the ON-versus-WHERE trap, FULL OUTER JOIN emulated in MySQL, CROSS JOIN grids, self joins for hierarchies and pairs, chains through junction tables with the fan-out problem, and semi and anti joins.
0/7 · 117 minPDF
08

Subqueries

Scalar subqueries and the second-highest salary, IN and EXISTS with multi-column IN and ANY/ALL, correlated subqueries for per-group comparisons and the latest row per group, derived tables that aggregate before joining, and why NOT IN returns nothing when a NULL appears.
0/6 · 102 minPDF
09

Set operations and CTEs

UNION and UNION ALL for stacking results, INTERSECT and EXCEPT with their NOT EXISTS and anti-join equivalents, the NOT IN null trap, common table expressions for naming the steps of a query, and recursive CTEs for org charts, category paths and date series.
0/5 · 84 minPDF
10

Window functions

OVER and PARTITION BY for aggregates that keep every row, ROW_NUMBER, RANK, DENSE_RANK and NTILE with their tie rules, LAG, LEAD and FIRST_VALUE for comparing neighbours, frames with ROWS and RANGE for running totals and moving averages, and the top-N-per-group pattern.
0/6 · 99 minPDF
11

Modifying data

INSERT with column lists, many rows and INSERT ... SELECT; UPDATE with expressions, CASE and values from another table; DELETE, TRUNCATE and DROP; MySQL upserts with ON DUPLICATE KEY UPDATE, REPLACE and INSERT IGNORE; and transactions with COMMIT, ROLLBACK and savepoints.
0/6 · 96 minPDF
12

Schema design

CREATE TABLE and choosing MySQL types; PRIMARY KEY, UNIQUE, NOT NULL, DEFAULT, CHECK and FOREIGN KEY; ALTER TABLE and DROP with safe migrations; normalization from 1NF to BCNF; one-to-many, many-to-many and self-referencing relationships; and views.
0/7 · 114 minPDF
13

Indexes and performance

B+tree indexes and InnoDB's clustered primary key, selectivity and the cost of every index, composite indexes and the leftmost prefix rule, reading MySQL's EXPLAIN and EXPLAIN ANALYZE, sargable predicates and their rewrites, and covering indexes.
0/6 · 100 minPDF
14

Transactions and concurrency

ACID and the InnoDB machinery behind it, the isolation levels and the dirty, non-repeatable and phantom reads they allow, row, gap and next-key locks, SELECT … FOR UPDATE, deadlocks and optimistic locking, MVCC with undo logs and read views, and savepoints.
0/6 · 100 minPDF
15

Query patterns

The shapes real reports and interview questions take: gaps and islands, deduplication, pivots, rolling windows, the nth highest value, and date series that fill the missing days.
0/7 · 122 minPDF
16

Interview idioms

The six classic SQL interview questions solved two ways, the theory drill from WHERE vs HAVING to ACID, the idiom sheet of question shapes and their queries, and the twelve pitfalls that quietly fail a query.
0/5 · 100 minPDF

Learn SQL: Free SQL Tutorial in 99 Lessons

Learn SQL free: 99 lessons in 16 modules, from first programs to interview questions, with exercises judged on MySQL 8 syntax on SQLite 3.49 and a certificate.

  • Language: SQL
  • Runtime: MySQL 8 syntax on SQLite 3.49
  • Modules: 16
  • Lessons: 99
  • Reading time: about 27 hours
  • Cost: Free on every plan, with a certificate

The language every backend, data and placement round asks for — SELECT and filtering, NULLs, functions, GROUP BY, joins, subqueries, CTEs, window functions, data changes, schema design, indexes and transactions — in MySQL 8, with every query judged in your browser's next second.

Syllabus

Module 1: Foundations

what a relational database is — tables, typed columns, rows without order, primary and foreign keys; SQL as a declarative language and its statement families; MySQL beside PostgreSQL, SQLite and SQL Server; the first SELECT; and the logical order a query's clauses run in.

Module 2: Selecting and filtering

aliases for columns and tables and where they work; calculated columns with arithmetic, decimal division, DIV, MOD, ROUND and CONCAT; WHERE with comparisons on numbers, text and dates; AND, OR and NOT with precedence and three-valued logic; IN, BETWEEN and LIKE; and DISTINCT with COUNT(DISTINCT).

Module 3: Sorting and limiting

ORDER BY with ASC and DESC, aliases, expressions and where NULLs sort; several keys, tie-breakers and custom orders; LIMIT and OFFSET with MySQL's comma form, TOP and FETCH FIRST; offset and keyset pagination; top-N queries and the Nth highest value.

Module 4: NULLs and expressions

NULL as a missing value, UNKNOWN and three-valued logic, IS NULL and MySQL's NULL-safe equality, COALESCE, IFNULL and NULLIF, searched and simple CASE, data types, DIV versus decimal division, implicit conversion and CAST.

Module 5: Functions

String functions to join, clean, cut and pad text; ROUND, CEIL, FLOOR, DIV and MOD; date types, date parts and DATE_FORMAT; date arithmetic with INTERVAL, DATEDIFF and TIMESTAMPDIFF; and IF, IFNULL, NULLIF, GREATEST and FIELD.

Module 6: Aggregation

COUNT, SUM, AVG, MIN and MAX and how they treat NULL; GROUP BY on columns and expressions; HAVING versus WHERE; conditional aggregation for counts, pivots and rates; GROUP_CONCAT; and the grouping mistakes — ONLY_FULL_GROUP_BY, the three COUNTs and averages of averages.

Module 7: Joins

INNER JOIN and row multiplication, LEFT and RIGHT JOIN with the ON-versus-WHERE trap, FULL OUTER JOIN emulated in MySQL, CROSS JOIN grids, self joins for hierarchies and pairs, chains through junction tables with the fan-out problem, and semi and anti joins.

Module 8: Subqueries

Scalar subqueries and the second-highest salary, IN and EXISTS with multi-column IN and ANY/ALL, correlated subqueries for per-group comparisons and the latest row per group, derived tables that aggregate before joining, and why NOT IN returns nothing when a NULL appears.

Module 9: Set operations and CTEs

UNION and UNION ALL for stacking results, INTERSECT and EXCEPT with their NOT EXISTS and anti-join equivalents, the NOT IN null trap, common table expressions for naming the steps of a query, and recursive CTEs for org charts, category paths and date series.

Module 10: Window functions

OVER and PARTITION BY for aggregates that keep every row, ROW_NUMBER, RANK, DENSE_RANK and NTILE with their tie rules, LAG, LEAD and FIRST_VALUE for comparing neighbours, frames with ROWS and RANGE for running totals and moving averages, and the top-N-per-group pattern.

Module 11: Modifying data

INSERT with column lists, many rows and INSERT ... SELECT; UPDATE with expressions, CASE and values from another table; DELETE, TRUNCATE and DROP; MySQL upserts with ON DUPLICATE KEY UPDATE, REPLACE and INSERT IGNORE; and transactions with COMMIT, ROLLBACK and savepoints.

Module 12: Schema design

CREATE TABLE and choosing MySQL types; PRIMARY KEY, UNIQUE, NOT NULL, DEFAULT, CHECK and FOREIGN KEY; ALTER TABLE and DROP with safe migrations; normalization from 1NF to BCNF; one-to-many, many-to-many and self-referencing relationships; and views.

Module 13: Indexes and performance

B+tree indexes and InnoDB's clustered primary key, selectivity and the cost of every index, composite indexes and the leftmost prefix rule, reading MySQL's EXPLAIN and EXPLAIN ANALYZE, sargable predicates and their rewrites, and covering indexes.

Module 14: Transactions and concurrency

ACID and the InnoDB machinery behind it, the isolation levels and the dirty, non-repeatable and phantom reads they allow, row, gap and next-key locks, SELECT … FOR UPDATE, deadlocks and optimistic locking, MVCC with undo logs and read views, and savepoints.

Module 15: Query patterns

The shapes real reports and interview questions take: gaps and islands, deduplication, pivots, rolling windows, the nth highest value, and date series that fill the missing days.

Module 16: Interview idioms

The six classic SQL interview questions solved two ways, the theory drill from WHERE vs HAVING to ACID, the idiom sheet of question shapes and their queries, and the twelve pitfalls that quietly fail a query.