Learn SQL in your browser
A free SQL tutorial in short lessons on one shop database. Every example runs on real PostgreSQL in your browser, and the page checks your answers.
Database design, migrations, SQL and everyday database work — explained with practical examples.
A free SQL tutorial in short lessons on one shop database. Every example runs on real PostgreSQL in your browser, and the page checks your answers.
Learn SQL MIN() and MAX() from short examples with their results: NULL values, dates and text, GROUP BY, HAVING, the row that holds the value, and OVER.
SQL tables on one three-row table: CREATE TABLE, data types, the primary key, CREATE TABLE AS, ALTER TABLE ADD, MODIFY and DROP COLUMN, TRUNCATE and DROP TABLE.
SQL ORDER BY on one five-row table: ASC and DESC, multiple columns, aliases, GROUP BY, CASE, LIMIT pages, NULLS FIRST and NULLS LAST, and ties.
Learn how SQL NULL values behave in WHERE, COALESCE, NULLIF, COUNT, AVG, ORDER BY, GROUP BY, joins, NOT IN and UNIQUE, from short queries and their results.
Learn SQL INSERT INTO SELECT from short examples with their results: the column list, constants, JOIN, NOT EXISTS, LIMIT and TOP, SELECT INTO, and the errors to expect.
Learn SQL joins from short examples with their results: INNER, LEFT, RIGHT, FULL, CROSS and SELF JOIN, a diagram of the rows each one returns, and the mistakes that drop or repeat rows.
Learn SQL COUNT, SUM and AVG from short examples with their results: COUNT(*) and COUNT(column), DISTINCT, NULL values, GROUP BY, HAVING and empty results.
Learn what a foreign key is from short examples with their results: FOREIGN KEY and REFERENCES, NULL, ADD and DROP CONSTRAINT, ON DELETE CASCADE and self-referencing keys.
Learn what a primary key in SQL is from short examples with their errors: PRIMARY KEY, composite keys, ALTER TABLE, foreign keys, UNIQUE, AUTO_INCREMENT and IDENTITY, in PostgreSQL, MySQL and SQLite.
Learn SQL AND, OR and NOT from short examples with their results: what each operator keeps, why AND binds before OR, and why NOT drops rows with NULL.