SQL practice
SQL practice: 10 exercises, a playground and lessons, all free
Every SQL practice question here runs against a real SQLite database inside your own browser: you write the query, press Run, and the result is checked against what the exercise asked for. Start with SELECT and WHERE, work up to JOINs, GROUP BY and window functions, and use the playground whenever you want to try a query of your own.
- checked exercises
- 10
- graded problems
- 0
- lessons
- 8
- cheat sheet
- 1
SQL practice exercises
How the path works →In order, each one introducing a single new idea. Press Run to check your answer; hints open one at a time.
- Your First SELECTSELECT names the columns you want back
- Pick the Right RowsAND narrows a filter while OR widens it
- The Dearest ThreeORDER BY is what makes LIMIT mean anything
- Tools per ShelfGROUP BY splits an aggregate into one answer per group, and HAVING filters those groups
- Name the ToolJOIN ... ON pairs rows from two tables by a matching column
- Nobody Left OutLEFT JOIN keeps unmatched rows, and count(*) then miscounts them
- Above the AverageA CTE names an intermediate result so a later step can use it
- The Missing WHEREUPDATE without WHERE changes every row, and a transaction is what makes a mistake undoable
- The Running TotalORDER BY inside OVER turns an aggregate into a running one
- Two per ShelfPARTITION BY restarts a window function's numbering for each group
SQL lessons behind the practice
All lessons →- SQL Tables, Rows and Your First SELECTLearn what a SQL table really is, how to create one and put rows in it, and how SELECT asks a database for exactly the columns you want — every example runnable in a real SQLite database in your browser.
- Filtering Rows in SQL with WHERECut a SQL result down to the rows you mean: comparison operators, AND, OR and brackets, IN, BETWEEN, LIKE pattern matching, and why NULL makes rows vanish from a filter that looks correct.
- Sorting and Limiting SQL Results: ORDER BY, LIMIT, DISTINCTPut SQL rows in a deliberate order with ORDER BY, take just the first few with LIMIT and OFFSET, and remove repeated rows with DISTINCT — including where NULLs and capital letters end up.
- SQL Aggregates, GROUP BY and HAVINGCollapse many SQL rows into one answer with COUNT, SUM, AVG, MIN and MAX, split the answer per group with GROUP BY, and filter the groups themselves with HAVING — plus what NULL does to every one of them.
- SQL Joins: INNER, LEFT, and Why Rows Duplicate or DisappearPut related SQL tables back together with INNER JOIN and LEFT JOIN, find the rows that have no match at all, and understand the two things that surprise everyone: a join that returns more rows than you started with, and one that returns fewer.
- SQL Subqueries and CTEs (WITH)Build a SQL query out of other queries: scalar subqueries, IN and EXISTS, derived tables, and common table expressions with WITH — including the aggregate-then-join pattern that fixes double counting.
- Changing Data Safely in SQL: INSERT, UPDATE, DELETE, TransactionsWrite to a SQL table without regretting it: INSERT and INSERT ... SELECT, UPDATE and DELETE with the WHERE you must not forget, transactions with BEGIN and ROLLBACK, and the constraints that stop bad rows getting in.
- SQL Window Functions: ROW_NUMBER, RANK and Running TotalsUse SQL window functions to see other rows without collapsing them: OVER and PARTITION BY, ROW_NUMBER and RANK for ranking and top-N-per-group, SUM() OVER for running totals, and LAG for row-to-row comparisons.
SQL cheat sheet
Everyday syntax on one page, for when you remember the idea but not the spelling.
SQL interview questions
Original questions with full model answers, for when the practice is going somewhere specific.
Questions people ask
- Is this SQL practice free?
- Yes. All 10 SQL exercises, the 8 lessons, the cheat sheet and the SQL playground are free, with no account and no email required.
- Do I need to install a database to practise SQL here?
- No. The queries run against SQLite compiled to WebAssembly, loaded into your browser tab. Nothing is installed on your computer and nothing you type is sent to a server.
- Which SQL dialect do the exercises use?
- SQLite. The core of SQL — SELECT, WHERE, ORDER BY, JOIN, GROUP BY, HAVING, subqueries, CTEs and window functions — is the same across SQLite, PostgreSQL and MySQL, so what you practise here carries over; only vendor-specific functions differ.
- Do the SQL practice questions come with answers?
- Each exercise has hints that open one at a time and a full solution query that unlocks once you have run your own attempt at least once, along with an explanation of the idea it teaches.
Practise another language
The same kind of practice hub exists for Python, JavaScript, TypeScript, Java, C++, C, C#, Go, PHP, Ruby, R and Bash & the Shell.