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
- Look at the Tables list to see the columns of
employeesanddepartments. - Type a query in the editor, or click a Sample query button such as JOIN or GROUP BY.
- Press Run query or Ctrl + Enter.
- Read the result table under the editor. Errors, such as a misspelt column name, show in red.
- 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. WriteWHERE dept_id IS NULLinstead. 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
- Start with what SQL is and the SELECT statement.
- Then practise SQL joins, GROUP BY and subqueries.
- Try window functions with the Window function sample query.
- Work through basic SQL queries with examples, then test yourself with SQL interview questions for freshers.
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.
