SQL Sandbox

Left pane: CREATE TABLE and INSERT to build sample data (products and order lines by default). Right pane: write a SELECT, pick a JOIN or GROUP BY example, then Run—JSON rows appear below the query. Everything executes in the browser; no database install or connection.

Learning SQL with in-memory relations

Relational databases store rows in named tables with typed columns. Primary and foreign keys express references between entities—orders point to customers, line items point to products. SELECT describes which columns to project, which rows pass predicates, how tables combine, and how groups aggregate.

A browser sandbox builds tiny tables from CREATE TABLE and INSERT, then evaluates read-only SELECT locally. That mirrors the logical model students use in courses and interviews without provisioning MySQL or PostgreSQL—while remaining a teaching engine, not a substitute for EXPLAIN, transactions, or vendor-specific functions.

Query practice — background

Tables, keys, and rows

  1. CREATE TABLE declares column names and coarse types; each INSERT adds one row to the heap-like store.
  2. Primary keys uniquely identify rows within a table; foreign keys reference another table’s key column.
  3. NULL marks missing values; comparisons and JOINs treat NULL with three-valued logic unless filtered explicitly.
  4. Semicolon-separated scripts run in order—later SELECT statements see rows inserted earlier in the same session.

How JOINs combine relations

  1. INNER JOIN keeps rows where the ON predicate matches pairs from both sides; non-matching rows disappear from the result.
  2. LEFT JOIN preserves every row from the left table and fills missing right-side columns with NULL when no match exists.
  3. Join order affects performance on real servers; for learning, focus on whether the predicate expresses the intended relationship.
  4. Cartesian products appear when JOIN is omitted or ON is always true—row counts multiply and filters become essential.

Filters, sort, and aggregation

  1. WHERE removes rows before grouping; only non-aggregated columns belong in simple WHERE clauses.
  2. GROUP BY collapses rows sharing key values; aggregate functions (COUNT, SUM, AVG) summarize each group.
  3. HAVING filters groups after aggregation—use it for conditions on SUM or COUNT, not raw row columns.
  4. ORDER BY sorts the final projection; LIMIT caps rows returned for pagination patterns.

How SELECT becomes rows: parser, planner, executor

  1. The parser builds a query tree from SQL text; syntax errors fail before any relation is touched.
  2. The planner chooses join order and access paths (sequential scan vs index) using statistics and cost models.
  3. The executor pulls tuples through the plan; projection and filtering happen as operators consume child rows.
  4. A result set is unordered unless ORDER BY is present—relational algebra treats relations as sets or bags, not lists.

Where a sandbox helps

JOIN and GROUP BY drills

Two-table schemas (products and order lines) make join keys tangible—change ON or add GROUP BY and compare row sets without installing a server.

Homework and interview checks

Paste the problem’s CREATE/INSERT, write the expected SELECT, and compare JSON output to the rubric before opening a corporate database client.

Frequently asked questions

How do I practice SQL online with sample tables?
Paste CREATE TABLE and INSERT in the left pane to define data, write a SELECT in the right pane, and click Run. Rows return as a JSON array in the output area—everything runs locally in the browser.
How do I test a SQL JOIN online?
Create two related tables with shared key columns, insert rows, then write SELECT … FROM … JOIN … ON …. The default products and order_lines example is ready to run; swap in your own schema for course problems.
Can I learn SQL online without installing a database?
Yes for read-only SELECT practice on tables you define. You do not get a persistent server, user accounts, or backup—use a real instance when you need transactions, indexes, and EXPLAIN.
What SQL is supported in this sandbox?
Common SELECT patterns: projections, WHERE, ORDER BY, INNER JOIN, GROUP BY, and simple aggregates on pasted tables. It is a learning engine, not full MySQL or PostgreSQL syntax.
How is this different from the SQL formatter?
The SQL formatter & beautifier only pretty-prints or minifies text without executing it. This page runs SELECT against your sample tables and returns JSON rows.
Why are results shown as JSON?
APIs and front-end apps often consume row arrays as JSON. After you inspect rows here, use JSON formatter & beautifier for tree view or minify when sharing fixtures.
What if the setup or query fails?
Messages distinguish sample-table SQL errors from query errors. Fix CREATE/INSERT syntax or the SELECT (missing columns, bad JOIN keys) and run again—empty input does nothing.
Can I practice INSERT, UPDATE, or DELETE?
Setup uses CREATE and INSERT to seed data; the query box is for SELECT. Mutating production-style DML belongs in a full database client with backups and permissions.