Advertisement

Online SQL Compiler

Write, run and test SQL code online, right in your browser. This free online SQL compiler needs no installation or signup — just type your code and click Run.

SQL is the standard language for creating, querying and managing relational databases. This editor uses SQLite, so you can create tables and run queries instantly.

How to use the SQL compiler

  1. Write your CREATE TABLE, INSERT and SELECT statements in the editor.
  2. Click Run.
  3. The query results appear in the output panel.

Sample SQL code

CREATE TABLE students (id INTEGER, name TEXT, marks INTEGER);
INSERT INTO students VALUES (1, 'Asha', 91), (2, 'Ravi', 78), (3, 'Meena', 85);

SELECT name, marks FROM students WHERE marks > 80 ORDER BY marks DESC;

More SQL examples to try

GROUP BY with aggregates

Counts orders and sums revenue per customer — the most common reporting query.

CREATE TABLE orders (id INTEGER, customer TEXT, amount REAL);
INSERT INTO orders VALUES
  (1, 'Asha', 250), (2, 'Ravi', 120), (3, 'Asha', 90),
  (4, 'Meena', 400), (5, 'Ravi', 60);

SELECT customer, COUNT(*) AS orders, SUM(amount) AS revenue
FROM orders
GROUP BY customer
HAVING SUM(amount) > 150
ORDER BY revenue DESC;

JOIN two tables

Combines rows from two tables using a shared key.

CREATE TABLE departments (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE employees (id INTEGER, name TEXT, dept_id INTEGER);
INSERT INTO departments VALUES (1, 'Engineering'), (2, 'Design');
INSERT INTO employees VALUES (1, 'Asha', 1), (2, 'Ravi', 2), (3, 'Meena', 1);

SELECT e.name, d.name AS department
FROM employees e
JOIN departments d ON d.id = e.dept_id
ORDER BY d.name, e.name;

Common SQL errors and how to fix them

no such table: users
The table has not been created in this run. Every run starts with an empty database, so include your CREATE TABLE and INSERT statements before the query.
near "FROM": syntax error
Usually a missing or extra comma in the column list, or a misspelled keyword just before FROM.
misuse of aggregate function
Aggregates such as SUM() cannot be used in WHERE. Filter grouped results with HAVING instead.
UNIQUE constraint failed
You inserted a duplicate value into a PRIMARY KEY or UNIQUE column. Use a different value, or INSERT OR REPLACE.

Frequently asked questions

Is this online SQL compiler free?

Yes. It is completely free to use, with no signup required to write and run code.

Do I need to install anything?

No. It all works from your web browser, so there is nothing to download or set up — it works on Windows, macOS, Linux, Chromebooks and phones.

Which database does this SQL editor use?

It uses SQLite, a lightweight SQL database. Create your tables and insert data in the editor, then query them — each run starts with a fresh database.

Is this good for learning SQL?

Yes. It is ideal for practising exercises, testing small programs and trying out ideas from tutorials, because you can run code instantly without configuring an environment.

Other online compilers

Editor powered by OneCompiler.