Query CSV with SQL

Run SQL queries directly on your CSV data.

About Query CSV with SQL

Answering a question like "which city brought the most revenue last month" from a CSV normally means importing it into a database or building a pivot table. This tool loads the CSV into an in-browser SQL engine (AlaSQL) so you can write a normal SELECT with WHERE, GROUP BY, ORDER BY, COUNT, SUM or AVG and see the result as a table, then download it as CSV.

Paste the CSV, write the query using FROM ? as the table name and click Execute. The engine runs inside your browser tab, so sales, HR or customer files are never uploaded to a server.

How to use Query CSV with SQL step by step

  1. Paste your CSV in the data box, replacing the sample orders table. The first line must contain the column names.
  2. Write the SQL query in the query box. The CSV is referenced as ? (question mark), for example SELECT * FROM ? WHERE amount > 100.
  3. Click "Execute query". The result appears as a table below; errors in the SQL are shown in red.
  4. Click "Download CSV" to save the result as query_result.csv.

Input and output example

Input

order_id,customer,city,amount
1001,Ana López,Madrid,120.50
1002,John Smith,London,89.90
1004,Luis García,Madrid,65.25

SELECT city, COUNT(*) AS orders, SUM(amount) AS revenue FROM ? GROUP BY city ORDER BY revenue DESC

Output

city   | orders | revenue
Madrid |      2 |  185.75
London |      1 |   89.9

Why use our Query CSV with SQL?

Common use cases

Limits and tips

Frequently asked questions

Why is the table called ? in the query?

The CSV rows are passed to the SQL engine as a parameter, and AlaSQL uses a question mark as a placeholder for a data source passed this way. Write FROM ? wherever you would write the table name; you can alias it with FROM ? AS t if you prefer.

Which SQL functions are supported?

The engine is AlaSQL, a JavaScript SQL database. It supports SELECT with WHERE, GROUP BY, HAVING, ORDER BY, LIMIT and OFFSET; aggregates COUNT, SUM, AVG, MIN, MAX; DISTINCT; CASE expressions; LIKE, IN and BETWEEN; and string and math functions such as UPPER, LOWER, TRIM, LENGTH, ROUND and ABS.

Why does SUM return 0 or a concatenated string?

Because the column contains values that are not plain numbers, for example 1,200.50 with a thousands separator, a currency symbol, or spaces. Only cells matching a plain decimal such as 1200.50 are converted to numbers. Clean the column first, or use CAST in the query.

What is the difference between running SQL on a CSV and in a database?

A database stores the data permanently, enforces types and indexes and can join many tables. Here the CSV is loaded into memory for one session and every column is text or number by inference, which is ideal for quick exploration but not for persistent or multi-table work.

Is the CSV sent to a server?

No. Parsing and query execution happen in JavaScript inside your browser. The data is discarded when you close or reload the page.

Related guides

Related tools

Other free utilities you may find useful

Available languages