SQL practice exercises with answers
88 exercises in 13 sets, taken from the sqlstreak course. Write the query in your browser, on real PostgreSQL or SQLite, and the checker tells you at once whether your result is right. Every answer is there when you need it.
- SELECT
SQL SELECT practice: 7 exercises with answers
Practise SQL SELECT on a real database in your browser: choose columns, calculate new ones, rename with AS and remove duplicates. Checked answers.
7 exercises · all from free lessons
- WHERE
SQL WHERE practice: 9 exercises with answers
Nine SQL WHERE exercises with checked answers: comparisons, true/false columns, AND and OR, IN and BETWEEN. Runs on PostgreSQL or SQLite in your browser.
9 exercises · all from free lessons
- ORDER BY and LIMIT
SQL ORDER BY and LIMIT practice: 7 exercises with answers
Practise sorting with ORDER BY, ASC and DESC, top-N with LIMIT and paging with OFFSET: seven exercises with checked answers on a real database.
7 exercises · all from free lessons
- NULL
SQL NULL practice: IS NULL, COALESCE and NULLIF exercises
Six SQL exercises on missing values: IS NULL, IS NOT NULL, COUNT(column), COALESCE and NULLIF, with checked answers. Runs in your browser.
6 exercises · 2 from free lessons
- Text
SQL text practice: LIKE patterns and string functions
Six SQL text exercises with answers: LIKE patterns with % and _, UPPER, joining text with ||, and SUBSTR. Checked on PostgreSQL or SQLite.
6 exercises · 3 from free lessons
- GROUP BY and HAVING
SQL GROUP BY and HAVING practice: 8 exercises with answers
Eight SQL exercises on COUNT, AVG, GROUP BY and HAVING, from counting rows to filtering groups. Checked answers, real PostgreSQL or SQLite.
8 exercises · 0 from free lessons
- JOIN
SQL JOIN practice: 6 exercises with answers
Practise SQL INNER JOIN on a pizza shop's orders: two tables, three tables, and joins with GROUP BY for totals and revenue. Checked answers.
6 exercises · 0 from free lessons
- LEFT JOIN
SQL LEFT JOIN practice: 6 exercises with answers
Six SQL LEFT JOIN exercises: keep rows without a match, find rows that never matched, count including zeros, and conversion funnels. Checked answers.
6 exercises · 0 from free lessons
- Subqueries
SQL subquery practice: 6 exercises with answers
Six SQL subquery exercises with checked answers: compare with an average, IN with a subquery, the maximum without LIMIT, and percentages.
6 exercises · 0 from free lessons
- CTEs
SQL CTE practice: WITH and WITH RECURSIVE exercises
Six SQL exercises on common table expressions: break a question into named steps with WITH, then generate numbers and dates with WITH RECURSIVE.
6 exercises · 0 from free lessons
- Window functions
SQL window functions practice: 8 exercises with answers
Eight SQL window function exercises: ROW_NUMBER, RANK, running totals with SUM OVER, LAG, totals on every row and NTILE. Checked answers.
8 exercises · 0 from free lessons
- Dates
SQL date practice: 7 exercises in PostgreSQL and SQLite
Seven SQL date exercises with answers for both PostgreSQL and SQLite: filter by date, extract the year and month, add days, count days, find Sundays.
7 exercises · 0 from free lessons
- Data cleaning
SQL data cleaning practice: 6 exercises with answers
Six SQL data cleaning exercises on a messy import: trim and lowercase text, count real people, turn text into numbers and find duplicates.
6 exercises · 0 from free lessons
Not sure where to start? Take the free SQL test, or begin with the first lesson.