Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

SQL Query Playground

Practice reading and writing SQL without installing a database. Type a query, see the result table update live, and watch the logical query plan rebuild as you add a JOIN, a filter, a group, or a sort. This is a teaching subset that runs in plain JavaScript on three fixed sample tables, so it is great for learning the order of operations rather than replacing a real database engine.

Sample queries

This runs a teaching subset of SQL on the three small sample tables below, not a full database engine. Supported clauses are SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT, with the aggregates COUNT, SUM, AVG, MIN and MAX. Unsupported syntax returns a short error.

Results

12 rows
nameproductamount
AvaLaptop1200
AvaMouse25
AvaMonitor250
BenDesk300
BenCable15
CaraLaptop1200
CaraMonitor250
CaraMouse25
DrewKeyboard75
EveDesk300
EveMouse25
FinnLaptop1200

Sample tables

Three fixed tables you can query. Click a sample query above or write your own.

customers(id, name, city, age)
idnamecityage
1AvaAustin34
2BenDenver28
3CaraAustin41
4DrewMiami23
5EveDenver37
6FinnAustin52
orders(id, customer_id, product, amount, status)
idcustomer_idproductamountstatus
1011Laptop1200shipped
1021Mouse25shipped
1032Desk300pending
1043Laptop1200shipped
1053Monitor250cancelled
1064Keyboard75shipped
1075Desk300shipped
1085Mouse25pending
1091Monitor250shipped
1106Laptop1200pending
1112Cable15shipped
1123Mouse25shipped
products(name, category, price)
namecategoryprice
LaptopElectronics1200
MouseAccessories25
DeskFurniture300
MonitorElectronics250
KeyboardAccessories75
CableAccessories15

Logical query plan

The order SQL applies your clauses, top to bottom. This is the logical plan, not a cost-based physical plan from a real database optimizer.

1Scan

customers c

2Scan

orders o

3Join

INNER on c.id = o.customer_id

4Project

c.name, o.product, o.amount

Reference Guide

SELECT, FROM and WHERE

SELECT. Chooses which columns to return. Use a star for every column, or list columns separated by commas, with an optional AS alias.

FROM. Names the base table the query reads. You can give it a short alias, for example customers c.

WHERE. Keeps only rows that satisfy a condition. Combine comparisons with AND and OR, where AND binds tighter. Operators are =, !=, <>, <, >, <=, >= and LIKE with the percent sign as a wildcard.

JOIN, inner versus left

A JOIN combines rows from two tables that share a matching value, for example c.id = o.customer_id.

INNER JOIN. Keeps only the pairs that match in both tables. Rows with no match are dropped.

LEFT JOIN. Keeps every row from the left table, filling the right table columns with NULL when there is no match. JOIN with no keyword means INNER.

GROUP BY and aggregates

GROUP BY collapses rows that share a value into one row per group. Aggregates then summarize each group.

Supported aggregates are COUNT, SUM, AVG, MIN and MAX. COUNT(*) counts rows, while SUM(amount) or AVG(amount) work on a column.

With aggregates but no GROUP BY, the whole table collapses to a single group. HAVING then filters groups after they are formed, for example HAVING COUNT(*) > 1.

ORDER BY and LIMIT

ORDER BY. Sorts the result by one or more columns, ascending by default or descending with DESC. You can sort by an aggregate too, for example ORDER BY SUM(amount) DESC.

LIMIT. Keeps only the first n rows after sorting, which is handy for a top three list.

The logical query plan

SQL does not run clauses in the order you write them. The logical order of operations is:

FROM → JOIN → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT

The plan panel rebuilds in this order as you edit the query, so you can see why a WHERE filter runs before grouping and why ORDER BY runs near the end.

What this tool is, and is not

This is a teaching subset of SQL implemented in plain JavaScript over three small sample tables. It is built to make the structure of a query and its order of operations visible.

It is not a full database. There is no INSERT, UPDATE, DELETE, subqueries, UNION, or window functions. Unsupported syntax returns a short, friendly error rather than crashing. Everything runs in your browser, so nothing is sent to a server.

Related Content