How to use the SQL Online Compiler
- 1. Pick or write a queryStart from an example or write your own SELECT, INSERT, UPDATE or CREATE.
- 2. Run itPress Run SQL or Ctrl + Enter. Several statements can run at once.
- 3. Read the resultsSee each result as a table, or download the last one as CSV.
The sample database
Three related tables load when you first run a query:
- departments(dept_id, dept_name, city): 4 rows: Engineering, Sales, Marketing and HR.
- employees(emp_id, name, dept_id, salary, hire_date, manager_id): 8 rows, including one person with no department and a few with managers.
- orders(order_id, emp_id, amount, order_date): 6 sales orders.
The data is small enough to check results by hand, but has the awkward cases interviews love: a NULL department, a department with no staff, and a self-referencing manager column. The engine is SQLite compiled to WebAssembly (sql.js), so this is a real database, not a simulation. Reset database puts everything back if you delete or change rows.
Worked example
The starter query joins employees to departments and groups them:
SELECT d.dept_name, COUNT(*) AS staff, AVG(e.salary) AS avg_salary
FROM employees e JOIN departments d ON d.dept_id = e.dept_id
GROUP BY d.dept_name ORDER BY avg_salary DESC;It returns 3 rows: Engineering, 3 staff, 78333.333333 (95,000 + 72,000 + 68,000 ÷ 3), then Marketing with 1 staff at 64000, then Sales with 3 staff at 52666.666667. Pooja is not counted because her dept_id is NULL, and HR is missing because nobody works there. Start FROM departments with a LEFT JOIN and count e.emp_id instead of * to see HR appear with 0 staff.
SQLite supports most standard SQL, including CTEs (WITH) and window functions such as RANK() and ROW_NUMBER(). Some details differ from MySQL: dates are stored as text, column types are flexible, and date functions use strftime() instead of MySQL's DATE_FORMAT(). Learn the standard parts here and they carry over to any database.
Frequently asked questions
Which SQL dialect is this?
SQLite, which follows standard SQL closely. Most SELECT, JOIN, GROUP BY and window function queries work the same in MySQL and PostgreSQL.
Are my changes saved?
Only until you reload the page or press Reset database. Nothing is stored on a server.
Can I create my own tables?
Yes. Run CREATE TABLE and INSERT statements, then query them like the sample tables.
Is the SQL compiler free?
Yes, free. Writing queries needs no form. The first Run asks for your name and WhatsApp number once, then every Uncodemy tool runs without the form.