DataSwitch Pro Private, in-browser data converter

SQL Query for CSV Files

Load CSV files into SQLite in your browser, query and join them with SQL, and download the result. Free, fast, and private.

Drop CSV files here, or click Add CSV files

Each file becomes a table named after the file. Add several to join them. Files are loaded into SQLite inside this tab and never uploaded.

How to query a CSV file with SQL

Updated · 6 min read

Spreadsheets are slow at questions like “total sales per city last month” or “which emails appear twice”, and they stop at a million rows. SQL answers them in one line. This tool loads your CSV files into a real SQLite database inside the browser, so you can query them like database tables without installing anything or uploading your data.

  1. Click Add CSV files or drop one or more files on the tool. Each file becomes a table named after it — sales 2024.csv becomes sales_2024 — with its columns typed as INTEGER, REAL, DATE or TEXT. If the columns look wrong, change Delimiter, Encoding or Types — the file reloads by itself.
  2. Write a query in the editor, or click one of the Examples made for your columns. Click a table or column name in the list to insert it.
  3. Press Run or Ctrl+Enter. To run only part of the editor, select it first. A long query can be stopped at any time.
  4. Scroll the result, then download it as CSV, Excel, TSV or JSON — the download contains every row, not just the ones on screen. SQLite .db saves all tables as one database file.

Your files stay on your device. They are read and queried in this browser tab; nothing is uploaded and nothing is kept after you close it.

What it does

Real SQLite, in your browser

The tool runs SQLite 3 compiled to WebAssembly in a background thread, so you get full SQL: joins, subqueries, CTEs (WITH), window functions, CASE, GROUP BY with HAVING, UNION, JSON functions and date functions.

Fast on big files

In our tests a 1,000,000-row CSV (73 MB) loaded in about 6 seconds; counting it took 0.03 s, grouping it 0.8 s and a LIKE search 0.1 s. Two million rows (145 MB) loaded in about 13 seconds.

Several files, one database

Add as many CSV files as you like and JOIN them — customers with orders, a price list with a stock export. CREATE TABLE … AS, UPDATE and DELETE work too, and new tables appear in the list.

Types that keep your data intact

A column becomes INTEGER or REAL only if every value in it is a plain number, so codes with leading zeros (00123), phone numbers and long IDs stay TEXT, exactly as written. Markers such as N/A, NULL or - become NULL instead of turning a number column into text, and decimal commas (2,5) are read as numbers in semicolon files. Set Types to All text to keep every value exactly as written.

Dates that sort and compare correctly

Dates such as 25/12/2024, 12/25/2024, 25.12.2024 or 2024/12/25 are stored as 2024-12-25, so ORDER BY, > and <, BETWEEN and strftime() give the right answer. The day/month order is read from the data itself, and the tool tells you when it had to assume it.

Extra functions for messy data

num(price) reads values like $1,200.50, 1.234,5 €, 45% or (300) as numbers. column REGEXP 'pattern' matches regular expressions, and lower() / upper() handle accented letters such as É, Ç and Ö.

Errors that tell you the fix

Instead of a bare SQLite message you get a hint: the column name you probably meant, the SQLite way to write SELECT TOP, NOW(), ILIKE or DATE_FORMAT from other databases, and a warning when curly quotes or an Arabic comma slipped into the query.

Private by design

Files are read and queried inside this tab. Nothing is uploaded, so you can query customer lists, finance exports or logs without sending them anywhere.

SQL cheat sheet for CSV data

Replace the table and column names with your own; the list next to the editor shows them.

Filter and sort

SELECT name, city, amount
FROM sales
WHERE city IN ('Rabat', 'Paris') AND amount > 100
ORDER BY amount DESC
LIMIT 50;

Group and total

SELECT city, COUNT(*) AS orders, ROUND(SUM(amount), 2) AS revenue
FROM sales
GROUP BY city
HAVING COUNT(*) >= 10
ORDER BY revenue DESC;

Join two CSV files

SELECT o.order_id, c.name, o.amount
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id;

Find duplicates

SELECT email, COUNT(*) AS copies
FROM contacts
GROUP BY lower(trim(email))
HAVING COUNT(*) > 1;

Totals per month (dates are stored as YYYY-MM-DD)

SELECT strftime('%Y-%m', order_date) AS month, SUM(amount) AS total
FROM sales
WHERE order_date BETWEEN '2025-01-01' AND '2025-12-31'
GROUP BY month
ORDER BY month;

Numbers written with $, % or thousands separators

SELECT product, SUM(num(price)) AS revenue
FROM sales
GROUP BY product
ORDER BY revenue DESC;

Match a pattern with REGEXP

SELECT * FROM contacts
WHERE email NOT REGEXP '^[^@\s]+@[^@\s]+\.[a-z]{2,}$';

Running total with a window function

SELECT order_date, amount,
       SUM(amount) OVER (ORDER BY order_date) AS running_total
FROM sales;

Column names with spaces

SELECT "Unit Price" * "Qty" AS line_total
FROM "order lines";

Save a cleaned table

CREATE TABLE clean AS
SELECT DISTINCT trim(name) AS name, lower(email) AS email
FROM contacts
WHERE email LIKE '%@%';

Common problems and fixes

no such column

Column names with spaces, dashes or other symbols must be in double quotes: "Unit Price". Click the column in the table list to insert it correctly. Text values go in single quotes: 'Paris'.

no such table

Tables are named after their files in lower case, with spaces and symbols turned into underscores, so Sales 2024.csv is sales_2024. The list on the left shows the exact names.

A number column sorts like text

When a column holds values such as $1,200, 45% or 5kg, it is kept as TEXT so nothing is lost — and the tool warns you when it loads. Read it as a number in the query: ORDER BY num(price) DESC or WHERE num(price) > 100.

Dates have the day and month swapped

When every date in a column fits both orders (for example 03/04/2025), the order is assumed from your browser's region and a note says so. If it is wrong, set Types to Numbers only to keep the dates exactly as written.

SELECT TOP, NOW() or ILIKE give an error

Those come from SQL Server, MySQL and PostgreSQL. In SQLite write LIMIT 10 at the end, datetime('now'), and plain LIKE (it already ignores case for A–Z). The error message shows the SQLite version of most such functions.

Everything is in one column

The delimiter was not detected. Choose it in Delimiter and the last file you added reloads with it.

Arabic or accented letters look wrong

The file is not UTF-8. Choose the encoding — for example Arabic (Windows-1256) — and the last file you added reloads with it.

The page ran out of memory

SQLite needs about two to three times the file size in memory. On a computer that is roughly 300 MB of CSV; on a phone, much less. Split the file, or use the command-line tools below.

Query CSV files with SQL from the command line

For a one-off question the tool above is fastest. For a job you repeat, or files of several gigabytes, these do the same in a script.

sqlite3 (command line)

.mode csv
.import sales.csv sales
SELECT city, SUM(amount) FROM sales GROUP BY city;

DuckDB (command line, very large files)

SELECT city, SUM(amount)
FROM read_csv_auto('sales.csv')
GROUP BY city;

Python (pandas + sqlite3)

import pandas as pd, sqlite3
con = sqlite3.connect(":memory:")
pd.read_csv("sales.csv").to_sql("sales", con, index=False)
print(pd.read_sql("SELECT city, SUM(amount) FROM sales GROUP BY city", con))

csvkit

csvsql --query "SELECT city, SUM(amount) FROM sales GROUP BY city" sales.csv

Frequently asked questions

How do I run SQL queries on a CSV file?

Add the CSV file to the tool on this page. It becomes a SQLite table named after the file, and you can query it with standard SQL — SELECT, WHERE, GROUP BY, JOIN and more — then download the result.

Can I join two CSV files with SQL?

Yes. Add both files; each becomes its own table. Then join them on a shared column, for example: SELECT * FROM orders JOIN customers ON customers.customer_id = orders.customer_id.

Which SQL dialect does it use?

SQLite 3, running in your browser through WebAssembly. Everything SQLite supports works, including common table expressions (WITH), window functions, JSON functions and date functions such as strftime().

Is my data uploaded?

No. The files are read and the database is built inside this browser tab. Nothing is sent to DataSwitch Pro or anyone else, and everything is gone when you close the tab.

How large a CSV file can I query?

On an ordinary computer, files up to roughly 300 MB work. In our tests a million rows loaded in about 6 seconds and most queries finished in well under a second. Phones have less memory, so stay smaller there.

How are column types chosen?

A column is INTEGER or REAL only if every one of its values is a plain number or an N/A-style marker; otherwise it is TEXT, so leading zeros and long IDs are kept exactly. Columns of dates become DATE and are stored as YYYY-MM-DD. Empty cells are stored as NULL, so COUNT(column) and AVG(column) skip them. The Types menu can turn date detection, or all detection, off.

Can I sort and filter by date when my file uses 25/12/2024?

Yes. Dates written day-first, month-first, with dots or with slashes are converted to YYYY-MM-DD when the file loads, so ORDER BY, BETWEEN and strftime('%Y-%m', column) work as expected.

Can I change the data with UPDATE or DELETE?

Yes. UPDATE, DELETE, INSERT and CREATE TABLE … AS work on the in-memory database. Your original files are never modified; download the result, or the whole database as a .sqlite file, to keep the changes.

Can I save my tables as a SQLite database?

Yes. Click SQLite .db to download every table as one database file that opens in DB Browser for SQLite, the sqlite3 command line, Python or any other SQLite tool.

Related tools