Skip to main content

SQLite Playground

Run SQLite queries on a small database in your browser, open or download a database file, browse tables and keep several SQL scripts.

-- Press Run (or Ctrl+Enter) to run this file. Every statement gets its own result table.

-- 1. Who works in Engineering, best paid first?
SELECT e.name, e.title, e.salary
FROM employees e
JOIN departments d ON d.id = e.department_id
WHERE d.name = 'Engineering'
ORDER BY e.salary DESC;

-- 2. How many people and what average salary per department?
SELECT d.name AS department, COUNT(*) AS people, ROUND(AVG(e.salary)) AS average_salary
FROM employees e
JOIN departments d ON d.id = e.department_id
GROUP BY d.name
ORDER BY average_salary DESC;

-- 3. Paid orders per month
SELECT strftime('%Y-%m', ordered_on) AS month, COUNT(*) AS orders, ROUND(SUM(amount), 2) AS total
FROM orders
WHERE status = 'paid'
GROUP BY month
ORDER BY month;

Results

Press Run to see the result tables here. The sample tables are listed on the right.

Shortcuts: Ctrl+Enter run · / search (use ⌘ on Mac)

Free Online SQLite Playground

Run SQL on a small database. A sample company database is ready (employees, departments and orders, about 200 rows), so you can try a query in seconds, or start empty and build your own tables. You can also open a SQLite file from your computer and download your database again. It all happens in your browser. It uses the real SQLite engine, so queries behave the way they do in your own projects.

How to use the playground

  1. Type SQL in the editor. End each statement with a semicolon. The tabs above the editor are separate script files.
  2. Press Run (or Ctrl+Enter) to run the open file. Select some text first to run only that part. Run all runs every file, from the first tab to the last.
  3. Read the results on the right: one table for each statement, with the number of rows and the time. A statement that changes data tells you how many rows it changed.
  4. Click a table name in the Schema list to add SELECT * FROM table LIMIT 100; to your file.
  5. Use Explain to see how SQLite plans the last statement, and the ⋯ menu to download the database, open a file, reset or change the time limit.

What happens when something goes wrong

A mistake shows the statement number, the line and what SQLite said, with a short tip. Statements before the mistake keep their effect and the ones after it do not run. If you need to format a long query first, try the SQL Formatter, or turn a JSON list into INSERT statements with JSON to SQL.

Worked example

With the sample database loaded, this query counts the people in each department and their average pay:

SELECT d.name AS department, COUNT(*) AS people, ROUND(AVG(e.salary)) AS average_salary
FROM employees e
JOIN departments d ON d.id = e.department_id
GROUP BY d.name
ORDER BY average_salary DESC;

The result has six rows. The first three are:

department | people | average_salary
-----------+--------+---------------
Finance    | 6      | 65733
Support    | 7      | 63711
Marketing  | 7      | 62341

Common mistakes

  • Forgetting the semicolon between two statements. SQLite then reads them as one and reports a mistake near the second word.
  • Using double quotes for text. In SQL, text goes in single quotes: 'Sales'. Double quotes are for names of tables and columns.
  • Writing = NULL to find empty values. Use IS NULL.
  • Expecting changes to stay after you close the tab. Download the database or press Save for your scripts.

Frequently asked questions

Is my data uploaded anywhere?
No. SQLite runs inside your browser and the database lives in its memory. Your queries, tables and any database file you open stay on your device, and closing the tab removes them unless you download the database or press Save.
How do I open a database file I already have?
Open the ⋯ menu and choose "Open a database file". Files that end in .db, .sqlite or .sqlite3 up to 50 MB work. If the file is not a SQLite database you get a message and your current database stays as it was.
Why did my query stop after 10 seconds?
A query that never ends would freeze the page, so the playground stops it after a time limit and puts the database back the way it was before that run. Look for a join with no matching condition or a recursive query with no end, or raise the limit in the ⋯ menu.
What are foreign keys and why is there a switch?
A foreign key links a row to a row in another table, for example an order to the employee who made it. With the switch on, SQLite refuses rows that point to something that does not exist. SQLite leaves this off by default, so turn it off here if you want to see that behaviour.
Why can I only see 1,000 rows?
Drawing a very long table would make the page slow, so each result shows the first 1,000 rows and tells you the full count. The Download CSV button next to the result saves the rows, up to 100,000 of them, to a file.
Do the .tables and .schema commands work?
No, those belong to the sqlite3 command-line program, not to SQL. Use the Schema list on the right instead, or ask the database with SELECT name FROM sqlite_master.
Can I use it to look inside a database file I downloaded?
Yes. Open the menu, choose to open a database file, and the tables appear in the schema list. The file is read in your browser and is never uploaded.

Related tools

More Playground

View all Playground tools →