Online SQL Compiler
queries.sql
Ready
About SQL
SQL is how you create, change and query data in relational databases. These queries run on MySQL: create your tables, insert rows, then SELECT from them, all in one script.
SQL programs to try
Copy one into the editor above and press Run.
Join two tables
CREATE TABLE depts (id INT, name VARCHAR(30));
CREATE TABLE emps (name VARCHAR(30), dept_id INT, salary INT);
INSERT INTO depts VALUES (1, 'Engineering'), (2, 'Sales');
INSERT INTO emps VALUES ('Asha', 1, 90000), ('Ravi', 2, 60000), ('Meera', 1, 85000);
SELECT e.name, d.name AS dept, e.salary
FROM emps e JOIN depts d ON e.dept_id = d.id;Second highest salary
CREATE TABLE emps (name VARCHAR(30), salary INT);
INSERT INTO emps VALUES ('Asha', 90000), ('Ravi', 60000), ('Meera', 85000);
SELECT MAX(salary) AS second_highest
FROM emps WHERE salary < (SELECT MAX(salary) FROM emps);Update and delete rows
CREATE TABLE items (id INT, name VARCHAR(30), qty INT); INSERT INTO items VALUES (1, 'pen', 10), (2, 'book', 0), (3, 'bag', 4); UPDATE items SET qty = qty + 5 WHERE name = 'bag'; DELETE FROM items WHERE qty = 0; SELECT * FROM items;
Common SQL errors and how to fix them
- ERROR 1064: You have an error in your SQL syntax
- Check the line near the quoted text for a missing comma, quote or keyword, and end every statement with a semicolon.
- ERROR 1146: Table doesn't exist
- Create the table earlier in the same script; each run starts with an empty database.
- ERROR 1054: Unknown column
- The column name is misspelled or belongs to another table. With joins, prefix it with the table alias.
Frequently asked questions
Is this online SQL compiler free?
Yes. Write and run SQL code in your browser for free, with nothing to install and no setup.
Which database does this run on?
MySQL. Each run starts with an empty database, so create your tables and insert data in the same script.
Can I practise SQL interview questions here?
Yes. Joins, GROUP BY, subqueries and window functions all work; create small sample tables and query them.
Does it work on my phone?
Yes. The editor, input and output work in a mobile browser, so you can practise SQL without a laptop.