SQL practice questions with answers
Practice SELECT, JOIN, GROUP BY, subqueries, CTEs, and window functions from beginner to advanced. Guided lessons run in your browser, include worked solutions, and grade your result against the expected output. The dataset collection adds 78 open-ended questions with revealed answers across 5 realistic schemas. There is nothing to install and nothing to sign up for.
New to SQL? Start at the top and follow the beginner path. Preparing for an interview? Jump to the interview sets, then use the topic paths to shore up anything that felt shaky. Already comfortable? Skip ahead to window functions, subqueries, and the reshaping reports. Those topics put more emphasis on result grain, tie handling, nulls, and other details that can make a syntactically valid query return the wrong answer.
Want questions tied to downloadable data?
Choose a dataset, work through its beginner, intermediate, and advanced questions, then reveal the tested SQL solution or open the prompt in the playground.
Start here: SELECT, WHERE, ORDER BY
The four moves every query is built from. Read a table, pick columns, filter rows, and sort the result.
Joins
Combine tables on a key, decide whether unmatched rows survive, and compare a table to itself.
Aggregates and grouping
Turn rows into totals, averages, and counts, then filter the groups themselves with HAVING.
Window functions and Top-N
Rank and total without collapsing rows, then keep the top row per group with a CTE/subquery or DuckDB's QUALIFY.
Subqueries and CTEs
Name query steps with WITH, compare rows to a benchmark value, and test for related rows with EXISTS.
Summary reports and reshaping
Build crosstabs and subtotal reports: conditional-aggregation pivots, ROLLUP, GROUPING SETS, and native PIVOT.
SQL interview questions
Interview-style prompts with model answers and the reasoning behind them.Prefer open-ended practice?
Once the guided questions feel easy, open the playground and write your own queries against the built-in datasets, or upload a CSV of your own. Same local engine, no grading in the way.
Are these SQL practice questions free?
Yes. SQLShed is free and requires no signup. The interactive SQL engine runs in your browser; queries and uploaded CSV data are processed locally rather than being sent to a SQLShed database server.
Do the practice questions come with answers?
Yes. Each lesson has a worked solution you can reveal, plus automatic grading that checks your query's result against the expected output, so you get instant feedback instead of guessing.
Which SQL dialect do the exercises use?
Exercises run on DuckDB compiled to WebAssembly. Many core patterns (SELECT, JOIN, WHERE, GROUP BY, CASE, and window functions) transfer across major SQL engines, but syntax and behavior still vary by dialect. SQLShed calls out DuckDB-specific features where they matter.