SQL Practice Questions

145 SQL problems for data engineering and analytics interviews: 73 easy, 57 medium and 15 hard. Each one gives you the tables, sample rows and the result to produce. Write the query in the browser, run it against the sample data, then submit it to be checked against hidden test cases. Free, and no setup or sign-in needed to start.

Start here:

SQL exercises for beginners

Start with filtering rows, then count records and join related tables. Each exercise supplies sample tables and an expected result, so you can focus on writing the query.

  1. Filter rows: Find All Products That Are Out of Stock
  2. Group and count: Count Total Orders Placed by Each Customer
  3. Join tables: Orders: List Orders With Customer Names (INNER JOIN)

Run checks your query on the sample data. Submit checks the returned rows against the exercise tests. SQL challenges use MySQL 8; keep columns in the order requested by the problem.

New to SQL? Follow the SQL beginner learning path, then return here to practise.

How SQL practice works here

SQL Window Functions practice (62)

ROW_NUMBER, RANK and DENSE_RANK, LAG and LEAD, running totals and moving averages: the pattern behind "top N per group", "compare with the previous row" and rolling metrics. All window functions problems →

SQL Joins practice (33)

INNER, LEFT and self joins, anti-joins ("customers who never ordered") and joins across three or more tables, including the NULLs a LEFT JOIN brings back. All joins problems →

SQL Aggregation practice (28)

GROUP BY with COUNT, SUM and AVG, HAVING versus WHERE, and conditional aggregation with CASE WHEN. All aggregation problems →

More SQL patterns (22)

CTEs and subqueries, date functions, deduplication with ROW_NUMBER, pivoting with CASE WHEN, DAU/WAU/MAU, funnels, sessions and gaps-and-islands.

Learn the concepts first

SQL window functions with examples · SQL CTEs: the WITH clause · SQL tutorials · SQL: beginner to advanced path · SQL interview questions

All coding challenges · All practice topics