ShareYourGroupShareYourGroupSQL

SQL practice box: run SQL in your browser

Type a query and press Run. The practice database is a small made-up shop with five tables. Everything runs inside your browser: nothing you type is sent anywhere, and Reset puts the database back as new.

The database loads the first time you press Run. On a keyboard, Ctrl + Enter also runs.

Tables in the practice database

Tap a table to see all its rows. Full details: the practice database.

Your last queries

  1. Nothing yet. Queries you run are remembered in this browser only.

How to use the practice box

  1. Type SQL in the box, or tap one of the table buttons to start with SELECT * FROM that table.
  2. Press Run. On a keyboard, Ctrl and Enter together do the same. The result appears as a table below, with the number of rows.
  3. Change the query and run it again. That loop of change, run and look is how SQL is learnt.
  4. Press Reset the database whenever you want the original data back, for example after trying UPDATE or DELETE.

The first time you press Run, the page loads the database engine, about 700 KB. After that it works at once, and on later visits it opens from your browser's saved copy, even without a connection.

What is in the database

TableRowsWhat it holds
customers12name, city, state, date joined, email (some missing)
products16name, category, price in rupees, stock
orders20which customer, the date, the status
order_items38the lines of each order: which product and how many
employees8name, department, salary, manager, date hired

The full contents of every table, with the column types and the links between tables, are on the practice database page. All names and figures are invented.

Queries to try

If you do not know where to start, copy one of these.

SELECT name, city FROM customers WHERE state = 'Punjab';
SELECT category, COUNT(*) AS products, ROUND(AVG(price)) AS average_price
FROM products
GROUP BY category
ORDER BY average_price DESC;
SELECT c.name, COUNT(o.id) AS orders
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.id, c.name
ORDER BY orders DESC, c.name;

Each idea in these queries has its own lesson. The lesson list starts from zero.

You can change the data too

The box accepts any SQL that SQLite understands: INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, CREATE VIEW, CREATE INDEX and the rest. You can build tables of your own and fill them. You may put several statements in the box, separated by semicolons. They run in order, and the result of each SELECT is shown.

Your changes last as long as the tab is open. Closing or reloading the page, or pressing Reset, brings back the original shop. Nothing is saved on any server, so do not use the box to keep anything you need.

Checking an exercise

When you open the box from an exercise, the question appears above the box and a Check my answer button appears beside Run. The check runs your query on a fresh copy of the database and compares your rows with ours. The exercises page lists every exercise and explains exactly what the check looks at.

Which SQL does it understand?

The engine is SQLite, a small, free database that is built into phones, browsers and countless apps. Its SQL is close to the standard. A few things differ from the big server databases:

The page on SQL in different databases lists these differences side by side.

If something goes wrong

This is an independent learning site. It is not connected with the makers of any database product. MySQL, PostgreSQL, SQL Server, Oracle and SQLite are named only so that you know where a piece of SQL works. The shop, its customers and its staff in the practice database are made up.