SQL on CSV: Query CSV Files with SQL
Load CSV or TSV files as tables and query them with real SQL (SQLite) in your browser.
Runs in your browser Your input never leaves your device.
Drop CSV or TSV files here, , or (up to 6 files; each becomes a table).
Files are read in this page and never uploaded. The SQL engine (about 0.7 MB) is downloaded the first time you run a query.
Report a problem with this tool
About this tool
Spreadsheets are awkward for questions like which department had the highest total sales per month, or which customers appear in one file and not the other. SQL answers them in a line. Drop one or more CSV or TSV files and each becomes a table named after the file; the tool detects the delimiter (comma, semicolon, tab or pipe), reads quoted fields and line breaks, cleans the header into column names that work in SQL, and decides for each column whether it holds whole numbers, decimals or text. Then write a query. The engine is SQLite, compiled to WebAssembly (sql.js), so you get joins, GROUP BY and HAVING, window functions such as RANK and running totals, common table expressions including recursive ones, date and string functions, and JSON functions. We compared it with Python's sqlite3 on 62 queries over generated tables, including joins, windows and recursive queries, and the rows were identical (only the SQLite version number and internal schema listings can differ). Click a table's SELECT * button or a column to insert it into your query, press Ctrl+Enter to run, and download the result as CSV or JSON. In CSV downloads, values that start with = + - or @ get a leading quote so a spreadsheet does not run them as formulas. How the files are read: empty fields become NULL; numbers with leading zeros, more than 15 digits, or decimal commas stay text so nothing is silently changed; a header name that is empty, repeated or a SQL keyword is renamed. Your files are read in the page and never uploaded, and the database exists only in memory: changes made with INSERT, UPDATE or DELETE last until you reload the tables or leave the page, and your original files are never modified. Queries run in a separate thread with a 20 second limit, up to 6 files of 30 MB and 300,000 rows each are accepted, and at most 50,000 result rows are kept.
How to use it
- Drop your CSV or TSV files on the page, or load the sample.
- Check the table names, columns and detected types.
- Write a SQL query, using the table and column buttons if you like, and press Run.
- Download the result as CSV or JSON.
Common problems
- A number column was treated as text
- Columns with leading zeros (like zip codes), values with more than 15 digits, decimal commas or any non-numeric value stay text. Convert in SQL with CAST(column AS REAL), after replacing the comma: CAST(REPLACE(price, ',', '.') AS REAL).
- It says no such column
- Column names were cleaned: spaces and symbols became underscores, and names that clash with SQL keywords got an underscore at the end. The table cards show the exact names; click one to insert it.
- Dates do not sort or compare correctly
- Dates are text. Use ISO format (2024-03-15) in the file, or convert in the query with substr and strftime. ISO dates sort correctly as text.
- The query was stopped after 20 seconds
- It may never end (an unbounded recursive query) or the data is large. Add LIMIT, filter earlier, or avoid joining big tables without a condition, which multiplies the rows.
- My changes disappeared
- The database is in memory only. Run SELECT queries and download the result, because INSERT, UPDATE and DELETE are lost when the tables reload.