SQL sandbox with tasks that check themselves

A real SQLite database in the browser with four datasets, 24 tasks that check the learner's answer, a classroom mode and links that share a query without storing anything. With the full task list, how the check works and ideas for class.

Web toolBachelor +2CC BY 4.0

What you will learn

  • Write queries across several tables with JOIN
  • Group and aggregate data with GROUP BY and HAVING
  • Use a subquery
  • Create a table and fill it with INSERT

What it is

A workspace for learning SQL that needs nothing but a browser. It runs SQLite, the database engine used in phones and browsers, compiled to WebAssembly.

  • Four databases: an office supplies shop (customers, products, orders and order items), school scores (students, courses and scores), an outreach campaign (companies, contacts, emails and deals) and an empty database for creating your own tables.

  • 24 tasks from a first WHERE to joins across three tables and a subquery. "Check my query" compares the learner's result with the expected one, row by row. A hint and the solution are one click away, never shown unasked.

  • The schema of every table, with a click to insert a table or column name.

Because it is real SQLite, everything SQLite can do works here: joins, subqueries, CASE, date functions, and statements that change data (CREATE TABLE, INSERT, UPDATE, DELETE). A change lasts until you press Reset data, switch the dataset or reload the page.

The Outreach campaign dataset follows a fictional B2B email campaign: 12 companies, 15 contacts, 27 emails in three steps with an A and a B version, and the 8 deals that followed. Its 12 tasks go from listing the contacts to reply rates per version, a compliance check (an opted-out contact who still got an email) and the pipeline the campaign brought.

The tasks

Office supplies shop

School scores

1. Cheap products (WHERE, ORDER BY)

1. Class 10a (WHERE, ORDER BY)

2. Customers in Germany (WHERE with text)

2. Average per course (JOIN, AVG, ROUND)

3. Orders with names (first JOIN)

3. Top in Computer Science (three tables)

4. Value of each order (JOIN, SUM, GROUP BY)

4. Courses per student (COUNT per group)

5. Customers without orders (LEFT JOIN, IS NULL)

5. Class averages (GROUP BY class)

6. Units by category (three tables, WHERE)

6. Above the average (subquery)

Outreach campaign

1. Everyone on the list (SELECT)

7. Replies per industry (two joins, GROUP BY)

2. Who said no (WHERE)

8. Nobody to write to (LEFT JOIN, IS NULL)

3. Bounces (COUNT)

9. A compliance check (GROUP BY, HAVING)

4. Emails per step (GROUP BY, ORDER BY)

10. Pipeline by stage (SUM per group)

5. Reply rate per version (ROUND, percentages)

11. Open pipeline (NOT IN)

6. Interested companies (two joins, DISTINCT)

12. What the campaign brought (subquery)

The same data can be downloaded: the shop as an SQL script, the school scores as a CSV file. Both pages list further tasks with checked answers.

How the check works

"Check my query" runs the learner's query and the task's solution side by side and compares the results:

  • The number of columns and the number of rows must match. If not, the message says how many the task needs.

  • The values must match. Column names do not count, so AS total or no alias are both right, and neither does the order of the columns: SELECT name, id is as right as SELECT id, name.

  • Row order only counts when the task asks for a sort. Then a result with the right rows in the wrong order gets its own message.

Because columns are compared in order, a result with the right columns in a different order is marked as "some values differ". If a learner is sure the result is right, compare its column order with the solution.

Hint shows a tip under the task. Solution puts the model query into the editor, replacing what is there. The counter shows how many tasks of the dataset are solved; it is not saved, so it starts at zero after a reload.

The editor and the results

  • SQL keywords, text and numbers are coloured. Ctrl+Enter (Cmd+Enter on a Mac) runs the query; Tab inserts two spaces.

  • Several statements, separated by semicolons, run in one go. The result table shows the last statement that returns rows.

  • The result shows up to 500 rows, how many rows there are in total and how long the query took. Empty values are shown as NULL.

  • The Tables panel lists every table with its number of rows, its columns, their types and the key column. It updates when you create a table.

Safe for school use

  • Everything runs on the learner's device. Queries are never sent to a server, and nothing is stored.

  • A query that runs too long is stopped after a few seconds and the database is reset, so a mistake cannot freeze the tab.

  • No account, no cookies needed, no personal data asked for.

Classroom mode (the button above the editor) hides the site header and footer, gives the workspace the whole screen and enlarges the text, so queries and results are easy to read on a projector. The bar at the top sets the text size and switches to full screen; Esc leaves it. On a phone the task comes first, then the editor and the result, then the tables.

Sharing without storing

"Share" turns the dataset, the query and the open task into a link. The information sits in the part of the address after #, which browsers never send to a server. A teacher can prepare a starting query and post the link; a shared query is only run when the learner presses Run.

Ideas for class

  1. Warm-up: everyone opens the shop database and runs SELECT * FROM customers to read the table together.

  2. Pairs: work through the shop tasks; the first pair with all six solved explains task 5 (customers without orders) to the class.

  3. Build your own: in the empty database, each group designs a table for something from school life (lending library, sports club) and writes three questions for another group.

  4. Prepared start: write the first line of a query, such as SELECT customers.name FROM customers, share the link, and let learners finish it.

  5. Break it on purpose: run the join from shop task 3 without its ON line and count the rows (80: every customer next to every order). Why?

  6. Hand in a link: learners solve a task of their own choice and send the Share link; opening it shows their exact query.

Full lesson plans: SQL basics exercise for the first keywords, the SQL joins lesson for 90 minutes on the shop tasks.

Common problems

  • "no such table". The table belongs to another dataset; check the dataset menu at the top left.

  • "no such column". A typo, or a column of another table. Click the name in the Tables panel instead of typing it.

  • Ambiguous column name. Two joined tables both have the column (often id). Write the table in front: customers.id.

  • The data looks wrong after an experiment. Press Reset data to get the starting tables back.

Reuse this material

CC BY 4.0

You may copy, adapt and share it, also commercially, as long as you credit ManyPI and link back.

"SQL sandbox with tasks that check themselves" by ManyPI (https://manypi.com/edu/sql-sandbox), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)