SQL Core
From your first SELECT to JOIN, subqueries, window functions, indexes, transactions and classic interview tasks, on PostgreSQL.
Tests check every exercise: in your browser and in the cloud
Syllabus
- What a database isTheory
- Tables, rows and columnsTheory
- Quiz — databases, rows and columnsQuiz
- Your first SELECTTheory
- Quiz — your first SELECTQuiz
- Exercise: names, categories and pricesExercise
- A query describes the resultTheory
- Quiz — what, not howQuiz
- Exercise: food from cheapest to priciestExercise
- Exercise: items over 250 rublesExercise
- Conditions and comparisonsTheory
- Quiz — conditions and comparisonsQuiz
- AND, OR, NOT and parenthesesTheory
- Quiz — AND, OR and NOTQuiz
- IN and BETWEENTheory
- LIKE and ILIKETheory
- Quiz — BETWEEN and LIKEQuiz
- Exercise: coffee and tea up to 200 rublesExercise
- Exercise: the regular menu from 200 to 300Exercise
- Exercise: everything with latteExercise
- What NULL isTheory
- Quiz — NULL and the empty stringQuiz
- Three-valued logicTheory
- Quiz — WHERE and UNKNOWNQuiz
- IS NULL and IS NOT NULLTheory
- NULL in expressions and sortingTheory
- Quiz — COALESCE and sorting NULLQuiz
- Exercise: items without a categoryExercise
- Exercise: everything but coffeeExercise
- Exercise: the menu by volumeExercise
- Aggregate functionsTheory
- Quiz — count and NULLQuiz
- GROUP BYTheory
- Quiz — the NULL groupQuiz
- HAVING and WHERETheory
- The order a query runs inTheory
- Quiz — the order a query runs inQuiz
- Exercise: a summary by categoryExercise
- Exercise: categories of the regular menuExercise
- Exercise: items without a volumeExercise
- INNER JOINTheory
- LEFT and RIGHT JOINTheory
- Quiz — which rows a join keepsQuiz
- FULL and CROSS JOINTheory
- Self-joinTheory
- Quiz — CROSS JOIN and self-joinQuiz
- Row multiplicationTheory
- A condition in ON or WHERETheory
- Quiz — repeated rows and WHEREQuiz
- Exercise: how many reports each manager hasExercise
- Exercise: October orders by shopExercise
- Exercise: customers without ordersExercise
- Scalar subqueryTheory
- Quiz — a scalar subqueryQuiz
- IN and EXISTSTheory
- Correlated subqueryTheory
- Quiz — IN and a correlated subqueryQuiz
- NOT IN and NULLTheory
- Subquery in FROMTheory
- Quiz — NOT IN and a subquery in FROMQuiz
- Exercise: the second-highest salaryExercise
- Exercise: contacts of customers without ordersExercise
- Exercise: below the shop's averageExercise
- UNION and UNION ALLTheory
- Quiz — what UNION keepsQuiz
- INTERSECT and EXCEPTTheory
- Quiz — INTERSECT, EXCEPT and NULLQuiz
- WITH: a query in stepsTheory
- Quiz — steps in WITHQuiz
- ★ Recursive WITHTheory
- Exercise: everyone in one listExercise
- Exercise: September, but not OctoberExercise
- Exercise: a shop's average checkExercise
- The window and OVERTheory
- PARTITION BYTheory
- Quiz — what the window seesQuiz
- ROW_NUMBER, RANK, DENSE_RANKTheory
- LAG and LEADTheory
- Quiz — places and the previous rowQuiz
- Running totals and the frameTheory
- Top N in each groupTheory
- Quiz — the frame and top NQuiz
- Exercise: running revenue by orderExercise
- Exercise: orders by month in each shopExercise
- Exercise: the best-paid staff in each shopExercise
- INSERTTheory
- Quiz — what INSERT addsQuiz
- UPDATETheory
- Quiz — which rows UPDATE changesQuiz
- DELETE and TRUNCATETheory
- RETURNING and ON CONFLICTTheory
- Quiz — DELETE, RETURNING and ON CONFLICTQuiz
- Exercise: repeat an orderExercise
- Exercise: a raise for busy baristasExercise
- Exercise: remove items nobody orderedExercise
- CREATE TABLE and typesTheory
- ConstraintsTheory
- Quiz — numbering and CHECKQuiz
- PRIMARY KEY and FOREIGN KEYTheory
- Quiz — CASCADE and SET NULLQuiz
- ALTER and DROPTheory
- NormalizationTheory
- Quiz — ALTER, DROP and normalizationQuiz
- Exercise: a table of promo codesExercise
- Exercise: menu reviewsExercise
- Exercise: payment methodExercise
- How the database finds rowsTheory
- The B-tree indexTheory
- Quiz — pages and indexesQuiz
- EXPLAINTheory
- Quiz — reading a planQuiz
- The composite indexTheory
- When an index doesn't helpTheory
- Quiz — column order and index trapsQuiz
- Exercise: an index for phone searchExercise
- Exercise: an index for a shop's ordersExercise
- Exercise: case-insensitive customer searchExercise
- BEGIN, COMMIT and ROLLBACKTheory
- ACIDTheory
- Quiz — commit, rollback and ACIDQuiz
- Concurrency anomaliesTheory
- Isolation levelsTheory
- Quiz — anomalies and isolation levelsQuiz
- Locks and FOR UPDATETheory
- Quiz — row locksQuiz
- Exercise: a transfer with a journal entryExercise
- Exercise: trying out new pricesExercise
- Exercise: pay only if there is enough moneyExercise
- How to solve an SQL taskTheory
- Exercise: orders of guests who share a phoneExercise
- Exercise: a report on the shopsExercise
- Exercise: the third price in each categoryExercise
- Exercise: regulars of one shopExercise
- Exercise: the top three items of each shopExercise
- Exercise: revenue growth in percentExercise
- ★ Exercise: orders on several days in a rowExercise