How to use the online SQL compiler
- Write your SQL in the editor. You can create tables (
CREATE TABLE), add data (INSERT) and query it (SELECT) in a single script. Separate statements with semicolons. - Press Run or use Ctrl + Enter (⌘ + Enter on a Mac).
- Every statement that returns rows is shown as its own result table, in order, with a row count underneath.
NULLvalues are labelled as such. If no statement returns rows, you'll see a short confirmation instead. - Choose a time limit of 5, 15 or 60 seconds, which is useful for runaway recursive queries. Stop cancels a query immediately.
The SQLite engine is small, well under 1 MB, so it loads almost instantly. Reset example restores the sample employees schema, and main.sql downloads your script.
Your queries run in a Web Worker in your own browser. Neither the SQL nor the data is uploaded or stored on our servers. The editor keeps your last script in your browser's local storage, and in no other place.
What's supported
The compiler runs SQLite 3 through sql.js, the SQLite C library compiled to WebAssembly. It is a real relational database engine, not an emulator.
- DDL and DML:
CREATE TABLE,CREATE INDEX,CREATE VIEW,INSERT,UPDATE,DELETE, constraints, foreign keys and triggers. - Queries: joins, subqueries,
GROUP BY/HAVING,UNION,CASE, and common table expressions, includingWITH RECURSIVE. - Window functions such as
ROW_NUMBER(),RANK(),LAG()and running totals withSUM() OVER (...). - Built-in functions for text (
substr,upper,replace), numbers, and dates (date,strftime).
Limitations:
- A fresh, empty in-memory database each run. Tables do not survive between runs, so keep your
CREATEandINSERTstatements at the top of the script. - It is SQLite, not MySQL or PostgreSQL. Most standard SQL works, but vendor-specific features such as stored procedures,
GRANT, MySQL'sAUTO_INCREMENTkeyword or PostgreSQL'sSERIALtype do not. - Large result sets show the first 1,000 rows, along with the total row count.
- You cannot connect to an external database or open your own
.dbfile.
SQL quick reference
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer TEXT NOT NULL,
amount REAL,
placed TEXT DEFAULT (date('now'))
);
INSERT INTO orders (customer, amount) VALUES
('Ada', 120.0), ('Ada', 35.5), ('Grace', 80.0);
WITH totals AS (
SELECT customer, SUM(amount) AS spent, COUNT(*) AS n
FROM orders
GROUP BY customer
)
SELECT customer, spent, n
FROM totals
WHERE spent >= 50 AND n <> 0
ORDER BY spent DESC;
| Task | SQL |
|---|---|
| Auto-numbered key | id INTEGER PRIMARY KEY |
| Filter rows | WHERE price BETWEEN 10 AND 20 |
| Pattern match | WHERE name LIKE 'A%' |
| Concatenate text | first || ' ' || last |
| Paginate | LIMIT 10 OFFSET 20 |
| Replace NULL | COALESCE(phone, 'n/a') |
| Insert or update | INSERT ... ON CONFLICT(id) DO UPDATE SET ... |
Tips
- Use
sqlite_masterto list what you have created:SELECT name, sql FROM sqlite_master; - Use
EXPLAIN QUERY PLAN SELECT ...to see whether a query uses an index. - SQLite uses flexible typing: a column declared
INTEGERcan still store text. AddCHECKconstraints, or useSTRICTtables, when you want type enforcement. - Foreign keys are only enforced after
PRAGMA foreign_keys = ON;. - Long, messy query? Clean it up with the SQL formatter before you share it.
BEGIN; … COMMIT;. Generating test data with a recursive CTE is a quick way to fill a table with thousands of rows for practice.Frequently asked questions
Which SQL dialect does this use?
SQLite 3. It follows standard SQL closely, so it is well suited to learning SELECT, joins, grouping and window functions. Syntax specific to MySQL, PostgreSQL or SQL Server may need small changes.
Is my data saved?
No. Each run creates a new in-memory database, which is deleted as soon as the run ends. Only the SQL text in the editor is remembered, locally in your browser.
Can I run several queries at once?
Yes. Separate them with semicolons. Statements run in order, and each one that returns rows produces its own result table.
Can I practise with other languages too?
Yes. Try the online Python compiler, where Python's built-in sqlite3 module works too, or browse all our developer tools.