SQL Query Builder

SQL Query Builder

All Games

Pick a difficulty, then build the correct SQL query by selecting the right option for each clause. A random puzzle from that level will be shown each time.

Choose Difficulty

About the SQL Query Builder Game

Writing SQL is easier to learn by doing than by reading. In the SQL Query Builder you get a table schema, a goal described in plain English and the expected result set. Your job is to build the query that produces it by choosing the correct option for each clause — SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY — and, in some puzzles, data-changing statements such as UPDATE, INSERT INTO and DELETE.

Puzzles come in three levels. Easy puzzles filter, group and total a single table; Medium adds extra conditions and data-modifying statements; Hard combines several conditions across groups and joins up to three tables. A live preview shows the query as you build it, and Run Query checks your answer against the expected output.

How to play

  1. Choose a difficulty. A random puzzle from that level is loaded.
  2. Study the Table Schema, the Goal and the Expected Output.
  3. Select an option for each clause and watch the Query Preview.
  4. Press Run Query. If it is wrong, Try Again; if it is right, load a New Puzzle.

Tips for a better score

  • Start from the expected output: which columns appear, and are any of them aggregates such as COUNT or SUM?
  • If the output has one row per group, you need GROUP BY. Every non-aggregated column in SELECT must appear in it.
  • WHERE filters rows before grouping; HAVING filters groups after aggregation.
  • Use LEFT JOIN when rows without a match must still appear in the result.

Frequently asked questions

How many puzzles are there?

There are 31 puzzles: 10 easy, 10 medium and 11 hard.

Which SQL dialect is used?

Most puzzles use standard SQL that works in SQL Server, PostgreSQL, MySQL and SQLite. A few hard puzzles are marked MS SQL Version and use SQL Server syntax.

Do I need a database installed?

No. Everything runs in the browser.

I am new to SQL. Where should I start?

Read the SQL basics guide, then play the Easy level. Use the SQL Query Analyzer to check queries you write yourself.

Related