Kodewick
Start learning →

Online SQL Compiler

Free, no database to install, sample data ready. Run a query, then watch it work clause by clause.

Try:
Online SQL CompilerFull screen · your code and output are still here
SQL
School
Example database
Examples
top-scoresquery.sql
SELECT s.name, c.title, e.score
FROM enroll e
JOIN student s ON s.id = e.sid
JOIN course c ON c.id = e.cid
WHERE e.score >= 90
ORDER BY e.score DESC;
Output

Press Run to see the result

MySQL 8.0Ln 1, Col 1Spaces: 4Learn SQL →Change it to keep it in My code
Not just run

Watch your query run: FROM → JOIN → WHERE → GROUP BY → ORDER BY

SQL is written in one order and worked out in another. Step through it: the table after each clause, the rows that JOIN pairs, the ones WHERE drops, the groups GROUP BY makes.

▶ Plays right here, no sign-in
Debug & share

Run it, pause it, replay it, share it

As handy as VS Code on your computer, plus what it does not have: every step drawn.

Step

One line at a time, every value beside it

Press Step and the code stops at each line: the lit line runs next, and every variable’s value sits beside it. Go back too, with the ← → keys.

One line at a time, every value beside it
Replay an error

It crashed? See exactly how it went wrong

Under the error, press “See how it went wrong”: the visualizer opens at the failing step, in red, with the reason in plain words. Step back through everything before it.

It crashed? See exactly how it went wrong
Share

A link, a GIF, a picture of the code: post it to X

A link opens this very code. Or export a GIF of it running (light or dark, wide or tall) or a picture of the code, and post it to X, a chat, or embed it in a blog.

A link, a GIF, a picture of the code: post it to X
Examples

12 SQL examples: one click runs them above

Each one can be stepped through and visualized. Change it, run it again.

SELECT and WHERE

Pick columns, keep the rows you want.

SELECT name, class
FROM student
WHERE gender = 'F';

ORDER BY and LIMIT

The three highest scores.

SELECT sid, cid, score
FROM enroll
ORDER BY score DESC
LIMIT 3;

COUNT, AVG, MAX

One row that sums up the whole table.

SELECT COUNT(*) AS n, AVG(score) AS avg_score, MAX(score) AS best
FROM enroll;

GROUP BY and HAVING

The average per course, only the courses above 80.

SELECT c.title, AVG(e.score) AS avg_score
FROM enroll e
JOIN course c ON c.id = e.cid
GROUP BY c.title
HAVING AVG(e.score) > 80
ORDER BY avg_score DESC;

INNER JOIN

Who scored 90 or more, and in which course.

SELECT s.name, c.title, e.score
FROM enroll e
JOIN student s ON s.id = e.sid
JOIN course c ON c.id = e.cid
WHERE e.score >= 90
ORDER BY e.score DESC;

LEFT JOIN and IS NULL

Students who take no course at all.

SELECT s.name
FROM student s
LEFT JOIN enroll e ON e.sid = s.id
WHERE e.sid IS NULL;

A subquery

Scores above the average of all scores.

SELECT sid, cid, score
FROM enroll
WHERE score > (SELECT AVG(score) FROM enroll)
ORDER BY score DESC;

CASE WHEN

Turn scores into grades.

SELECT sid, score,
  CASE
    WHEN score >= 90 THEN 'A'
    WHEN score >= 75 THEN 'B'
    WHEN score >= 60 THEN 'C'
    ELSE 'F'
  END AS grade
FROM enroll
ORDER BY score DESC;

Window functions: RANK()

Rank within each course, without grouping the rows away.

SELECT cid, sid, score,
  RANK() OVER (PARTITION BY cid ORDER BY score DESC) AS rnk
FROM enroll
ORDER BY cid, rnk;

What each customer spent

Three tables joined, SUM per customer (the Shop database).

SELECT c.name, SUM(p.price * i.qty) AS spent
FROM customer c
JOIN orders o ON o.customer_id = c.id
JOIN order_item i ON i.order_id = o.id
JOIN product p ON p.id = i.product_id
GROUP BY c.name
ORDER BY spent DESC;

A self join: who is whose boss

The same table twice (the Company database).

SELECT e.name AS employee, m.name AS boss
FROM emp e
LEFT JOIN emp m ON m.id = e.manager_id
ORDER BY e.id;

CREATE, INSERT, UPDATE, DELETE

Your own table: change it and see the result. “Reset” puts the sample data back.

CREATE TABLE todo (
  id INT PRIMARY KEY,
  task VARCHAR(30),
  done INT DEFAULT 0
);
INSERT INTO todo (id, task) VALUES (1, 'learn SELECT'), (2, 'learn JOIN'), (3, 'learn GROUP BY');
UPDATE todo SET done = 1 WHERE id = 1;
DELETE FROM todo WHERE id = 3;
SELECT * FROM todo;
Three steps

How to run SQL online

  1. 1
    Write code, or pick an exampleThe editor works like VS Code: completion, matching brackets, Ctrl+/ to comment.
  2. 2
    Press Run, or Ctrl + EnterThe output shows beside the code.
  3. 3
    To see how it runs: Step, or VisualizeYour code is kept in this browser; find it again in My code.
What works

SQL, running in your browser

✓ Works

  • SELECT with JOIN (inner, left, right), GROUP BY, HAVING, ORDER BY, LIMIT
  • Subqueries, CASE, window functions (RANK, ROW_NUMBER, SUM OVER …)
  • CREATE TABLE, INSERT, UPDATE, DELETE
  • Three sample databases: School, Shop, Company
  • MySQL 8.0’s results and error messages

✕ Not yet

  • Stored procedures, triggers, users and permissions
  • Other dialects’ own syntax (PostgreSQL, SQL Server …)
  • Connecting to your own database
  • Keeping data between visits (Reset puts it back)
FAQ

About the online SQL compiler

Is it free? Do I need an account?

No and no. Open the page and write SQL; there is nothing to install.

Which database is it?

MySQL 8.0’s dialect, run by our own engine in your browser: the same results and the same error messages for what it supports.

What tables are there?

Three sample databases, picked from the database menu: School (student, course, enroll), Shop (customer, product, orders, order_item) and Company (dept, emp).

Can I create my own tables?

Yes: CREATE TABLE, INSERT, UPDATE and DELETE all work. Press Reset to put the sample data back.

What does the visualizer show?

The query in the order it is worked out — FROM, JOIN, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT — and the table after each one.

Is it good for interview practice?

Yes: joins, grouping, subqueries and window functions are the usual questions, and seeing each step is the quickest way to understand a wrong answer.

Does it work on a phone?

Yes. Tap the code to write full screen, with keys for brackets, commas, quotes and *.

How do I share a query?

Share → Copy link: it opens the same query on the same database. You can also export a GIF of it running, or a picture of it.

More

Four more languages, the same tools