Online SQL Compiler
Create tables, add data and run queries. The results appear as tables.
About this SQL compiler
This free online SQL compiler runs SQLite in your own browser. Write CREATE TABLE, INSERT and SELECT statements, press Run, and see each result as a table. Every run starts with a fresh, empty database, so you can try anything without breaking something.
It is made for practising SQL for interviews, college DBMS lab work and data analyst roles.
How to use it
- Create a table with CREATE TABLE and add rows with INSERT.
- Write one or more SELECT queries. End each statement with a semicolon.
- Press Run. Each SELECT shows its own result table.
SQL examples
Open any of these from the Examples tab in the side bar.
Create, insert and select
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
city TEXT,
marks INTEGER
);
INSERT INTO students (name, city, marks) VALUES
('Asha', 'Pune', 82),
('Ravi', 'Delhi', 67),
('Meera', 'Pune', 91),
('Kabir', 'Chennai', 54);
SELECT name, marks FROM students WHERE marks > 60 ORDER BY marks DESC;
GROUP BY with an average
CREATE TABLE students (name TEXT, city TEXT, marks INTEGER);
INSERT INTO students VALUES
('Asha', 'Pune', 82), ('Ravi', 'Delhi', 67),
('Meera', 'Pune', 91), ('Kabir', 'Chennai', 54);
SELECT city, COUNT(*) AS students, ROUND(AVG(marks), 1) AS avg_marks
FROM students
GROUP BY city
ORDER BY avg_marks DESC;
JOIN two tables
CREATE TABLE courses (id INTEGER PRIMARY KEY, title TEXT);
CREATE TABLE enrolments (student TEXT, course_id INTEGER);
INSERT INTO courses VALUES (1, 'Python'), (2, 'SQL'), (3, 'React');
INSERT INTO enrolments VALUES ('Asha', 1), ('Asha', 2), ('Ravi', 2), ('Meera', 3);
SELECT e.student, c.title
FROM enrolments e
JOIN courses c ON c.id = e.course_id
ORDER BY e.student;
What is SQL?
SQL (Structured Query Language) is the language for working with data in tables. Almost every company stores its data in a SQL database, so SQL is asked in interviews for developer, data analyst and data science roles.
This page uses SQLite. SQLite follows standard SQL, so SELECT, WHERE, JOIN, GROUP BY, ORDER BY and subqueries work the same as in MySQL and PostgreSQL. A few details are different, listed in the questions below.
Common errors and how to fix them
no such table: studentsEach run starts with an empty database. Put the CREATE TABLE and INSERT statements in the same run as your SELECT.near "…": syntax errorCheck for a missing comma between columns or a missing semicolon between statements.UNIQUE constraint failedYou inserted a value that already exists in a PRIMARY KEY or UNIQUE column.
Frequently asked questions
Is this MySQL?
No, it is SQLite, which runs in your browser. Most queries are the same. Differences: use INTEGER PRIMARY KEY instead of AUTO_INCREMENT, and SELECT name FROM sqlite_master instead of SHOW TABLES. Stored procedures are not supported.
Is my data saved?
No. Each run uses a new empty database. This keeps every practice run clean and repeatable.
Where does the query run?
In your browser. Nothing is sent to our server.
Can I use JOIN and GROUP BY?
Yes. JOIN, LEFT JOIN, GROUP BY, HAVING, ORDER BY, subqueries and window functions such as ROW_NUMBER() all work.
Is it free?
Yes, and it works without an account.
Other free compilers
Learn to code with DevHives
Step-by-step lessons, DSA problems with a judge and mock interviews — made for students in India.
Create a free account