Text & Developer tool

Online SQL Compiler: Practice Queries Free

Run real SQL queries on sample tables, right in your browser.

  • Instant results
  • Working shown
  • No sign-up
  • Runs in your browser
ToolUpdates as you type
Sample queries:
Tables

Loading…

Loading the SQL engine…

A real SQLite database runs inside your browser. Nothing is sent to a server and nothing is saved: reloading the page brings back the original sample tables. A query that runs longer than 5 seconds is stopped.

How it works

This online SQL compiler runs a real SQLite database inside your browser. Two sample tables, employees and departments, are already loaded, so you can type a SELECT query and press Run straight away. You can also create tables, insert rows and update data. Reset brings back the original sample tables.

This online SQL compiler lets you practise SQL without installing anything. A real SQLite database runs in your browser with two sample tables already filled in: employees and departments. Type a query, press Run query, and see the result as a table.

How to run SQL online

  1. Look at the Tables list to see the columns of employees and departments.
  2. Type a query in the editor, or click a Sample query button such as JOIN or GROUP BY.
  3. Press Run query or Ctrl + Enter.
  4. Read the result table under the editor. Errors, such as a misspelt column name, show in red.
  5. Click Reset sample tables to undo any INSERT, UPDATE, DELETE or DROP you ran.

You can run several statements at once by ending each with a semicolon. Each SELECT gets its own result table.

The sample tables

departments

dept_id dept_name location
1 Engineering Hyderabad
2 Data Analytics Bengaluru
3 Human Resources Hyderabad
4 Sales Pune
5 Marketing Chennai

employees has 12 rows with these columns:

Column Type Notes
emp_id INTEGER Primary key, 101 to 112
name TEXT Employee name
job_title TEXT For example Developer, Data Analyst
dept_id INTEGER Links to departments. One intern has NULL
manager_id INTEGER Links to another employee. The top manager has NULL
salary INTEGER Monthly salary in the sample data
hire_date TEXT Date as YYYY-MM-DD

The data is made up for practice. It includes a department with no employees and an employee with no department, so you can see how LEFT JOIN and NULL behave.

Practise SQL online: queries to try

Filter and sort. This returns the 7 employees earning more than 60,000, highest first:

SELECT name, job_title, salary
FROM employees
WHERE salary > 60000
ORDER BY salary DESC;

The first rows are Anil Kumar (150000), Priya Sharma (110000) and Lakshmi Iyer (98000).

Count employees in every department. LEFT JOIN keeps Marketing even though nobody works there:

SELECT d.dept_name, COUNT(e.emp_id) AS employees
FROM departments d
LEFT JOIN employees e ON e.dept_id = d.dept_id
GROUP BY d.dept_id
ORDER BY employees DESC;
dept_name employees
Engineering 4
Data Analytics 3
Human Resources 2
Sales 2
Marketing 0

Second highest salary. A classic interview question:

SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

This returns 110000. See how to find the second highest salary in SQL for other ways to solve it.

Change data. Try an UPDATE, then run a SELECT to check it:

UPDATE employees SET salary = salary + 5000 WHERE dept_id = 4;
SELECT name, salary FROM employees WHERE dept_id = 4;

The tool tells you how many rows changed. Pooja Verma becomes 45000 and Arjun Mehta 95000.

Common mistake: A common mistake is writing WHERE dept_id = NULL. That never matches, because NULL is not equal to anything, not even NULL. Write WHERE dept_id IS NULL instead. Try both on the sample tables and compare.

SQLite vs MySQL: what to know

This SQL playground uses SQLite, which is small enough to run in a browser. Most beginner queries work the same as in MySQL. A few differences:

Topic SQLite (this tool) MySQL
Auto-numbered IDs INTEGER PRIMARY KEY INT AUTO_INCREMENT PRIMARY KEY
Data types Flexible: a column accepts other types Strict types
Dates Stored as text, date('now') DATE type, CURDATE()
Show tables Use the Tables list here SHOW TABLES;
Joins, GROUP BY, subqueries, CTEs, window functions Supported Supported (window functions from MySQL 8)

For more on the difference between the language and the database products, read SQL vs MySQL.

Learn SQL step by step

Pro tip: Before writing a long query, run SELECT * FROM employees LIMIT 5; to look at the data. Knowing what the rows look like makes it much easier to write the right WHERE and JOIN conditions.

Frequently asked questions

Do I need to install MySQL to practise SQL?
No. This SQL playground runs SQLite in your browser, so there is nothing to install and no account to create. When you are ready for a full database on your laptop, see how to install MySQL.
Which SQL does this compiler use?
SQLite. SELECT, WHERE, ORDER BY, JOIN, GROUP BY, HAVING, subqueries, CTEs and window functions work the same way as in MySQL for almost every beginner query. A few things differ, such as date functions and how auto-numbered IDs are declared.
Can I create my own tables?
Yes. Run CREATE TABLE and INSERT statements, and your new table appears in the Tables list. Everything stays only in this browser tab, so it is gone when you reload the page.
Is my data sent to a server?
No. The database engine is downloaded once and then every query runs on your own computer. Nothing you type is uploaded.
Why did my query stop with a time limit message?
Queries that run longer than 5 seconds are stopped so the page does not freeze. This usually means a recursive CTE with no stopping condition. The sample tables are reset after that.

Try another tool

See all free tools
Chat with us