Skip to content
Practice questions

SQL practice questions, grouped by topic.

Every exercise here runs in your browser on real datasets, comes with a worked solution, and grades your answer against the expected result the moment you run it. There is nothing to install and nothing to sign up for. Pick a topic below and work down the path: each one moves from a first lesson to the trickier cases, then points you at the interview questions and the common mistakes that trip people up on that exact topic.

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. The questions there are the ones that separate a working query from a correct one.

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 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

Timed-feeling 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.

Questions about practising SQL here

Are these SQL practice questions free?

Yes. Every lesson, interview question, and dataset on SQLShed is free and runs entirely in your browser. There is no signup, no server, and nothing you write is uploaded.

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. The core SQL is standard and transfers to Postgres, MySQL, SQL Server, and BigQuery, and pages flag any DuckDB-specific syntax where it comes up.