liminfo

SQL Playground

Free web tool: SQL Playground

Schema: users, orders, products

users

id, name, email, age, city

5 rows

orders

id, user_id, product, amount, date

8 rows

products

id, name, category, price, stock

8 rows

Supported SQL Syntax

SELECT

SELECT cols FROM table [JOIN table ON ...] [WHERE ...] [GROUP BY ...] [ORDER BY ...] [LIMIT n]

JOIN

INNER JOIN / LEFT JOIN table ON a.col = b.col

GROUP BY

GROUP BY col + SUM, AVG, MAX, MIN, COUNT

UPDATE / DELETE

UPDATE t SET col=val WHERE ...
DELETE FROM t WHERE ...

About SQL Playground

The SQL Playground is an in-browser SQL execution environment preloaded with three relational tables: `users` (id, name, email, age, city — 5 rows), `orders` (id, user_id, product, amount, date — 8 rows), and `products` (id, name, category, price, stock — 8 rows). You can write and run SQL queries directly in the textarea, see results in a formatted table, and maintain a history of the last 10 queries you ran. No database installation, no cloud credentials, and no backend is required.

SQL beginners learning their first queries, developers testing JOIN logic mentally using the schema, instructors demonstrating SELECT syntax, and anyone who needs to quickly verify how SQL clauses like WHERE, ORDER BY, LIMIT, and COUNT work will find this tool immediately useful. The schema mirrors common real-world e-commerce patterns — users placing orders for products — making the sample data relatable and the query examples meaningful.

The SQL parser is a pure JavaScript implementation that handles SELECT with column projection, WHERE conditions (=, !=, >, <, >=, <=, LIKE), ORDER BY with ASC/DESC, LIMIT, aggregate COUNT(*), INSERT INTO with values, SHOW TABLES, and DESCRIBE. Queries execute instantly with results displayed in a scrollable table. Ctrl+Enter runs the query without clicking the button. A dropdown of seven example queries helps beginners get started immediately.

Key Features

  • Three preloaded tables: users (5 rows), orders (8 rows), products (8 rows) with realistic e-commerce data
  • SELECT with full column list or wildcard (*), column projection, WHERE conditions, ORDER BY ASC/DESC, LIMIT, and COUNT(*)
  • WHERE clause supports six comparison operators (=, !=, >, <, >=, <=) and LIKE for substring matching
  • INSERT INTO support to add rows to any table during the session
  • SHOW TABLES and DESCRIBE to inspect the database schema without memorizing table names
  • Query history showing the last 10 executed queries for quick re-execution
  • Ctrl+Enter keyboard shortcut to run queries without leaving the keyboard
  • Seven built-in example queries selectable from a dropdown for immediate hands-on learning

Frequently Asked Questions

What SQL statements does this playground support?

The playground supports SELECT (with column projection, WHERE, ORDER BY ASC/DESC, LIMIT, and COUNT(*) aggregate), INSERT INTO (with explicit column and value lists), SHOW TABLES, and DESCRIBE. It does not support UPDATE, DELETE, CREATE TABLE, DROP, or JOIN operations — those require a full database engine.

What tables are available and what data do they contain?

Three tables are preloaded. `users` has columns id, name, email, age, city with 5 rows (Alice in New York, Bob in San Francisco, Charlie in Chicago, Diana in New York, Eve in Boston). `orders` has id, user_id, product, amount, date with 8 rows of product purchases. `products` has id, name, category, price, stock with 8 electronics and accessories items.

How do I filter results with WHERE?

Add a WHERE clause after the table name: `SELECT * FROM users WHERE city = 'New York'` returns Alice and Diana. `SELECT * FROM orders WHERE amount > 500` returns orders over $500. `SELECT * FROM users WHERE name LIKE '%li%'` returns rows where the name contains "li". Wrap text values in single quotes.

How do I sort results?

Add ORDER BY followed by a column name and optionally ASC (default) or DESC: `SELECT * FROM orders ORDER BY amount DESC` shows the most expensive orders first. `SELECT * FROM products ORDER BY price ASC` shows cheapest products first.

Does data persist between page reloads?

No. The database is initialized fresh in memory each time the page loads. Any rows added with INSERT INTO exist only for the current session and are lost on page refresh. This is intentional — the playground is a safe sandbox where every session starts from the same known state.

Can I practice JOIN queries here?

The current parser does not support JOIN syntax. To simulate a join mentally, you can first query `SELECT * FROM orders WHERE user_id = 1` to find Alice's orders, then cross-reference with `SELECT * FROM products WHERE name = 'Laptop'`. Full JOIN support would require integrating a complete SQL engine like sql.js (SQLite compiled to WebAssembly).

Why does COUNT(*) only work with SELECT count(*)?

The parser handles COUNT(*) as a special case in the column projection phase: when it detects a `count(` substring in the SELECT list, it returns a single row with the count of filtered rows. Other aggregate functions like SUM, AVG, MAX, and MIN are not currently implemented.

How do I use this to learn SQL basics?

Start with the example queries in the dropdown: run `SELECT * FROM users` to see all data, then try `SELECT name, email FROM users WHERE age > 25` to practice projection and filtering. Use `SELECT * FROM orders ORDER BY amount DESC` to learn sorting, and `SELECT count(*) FROM orders` to learn aggregation. Each query result appears immediately below, making the connection between SQL and output intuitive.