CSV analysis
How to Query CSV Files with SQL in Your Browser
Use SQL for Files as a local CSV analysis workspace: add a file, inspect the generated table, write SQL, and export the rows you need.
On This Page
Why query CSV files with SQL?
CSV is easy to export but awkward to inspect once files grow beyond a few thousand rows. SQL gives you a direct way to filter, group, sort, and join CSV data without first importing it into a spreadsheet or database server.
- Filter rows with WHERE instead of manual spreadsheet filters.
- Summarize numeric columns with COUNT, SUM, AVG, MIN, and MAX.
- Join multiple CSV files when IDs or names connect them.
- Export a smaller result set after the query is finished.
Add a CSV file
- Open the SQL for Files editor.
- Drag a CSV file into the Add Data area, or choose it from your file picker.
- Review the detected table name in the Database sidebar.
- Expand the table to inspect column names before writing a query.
Advanced CSV options
If your CSV uses a custom delimiter, skipped rows, unusual quote character, or a regional decimal separator, use advanced add options before creating the table.
Start with simple queries
Begin with a small preview query so you can verify column names and row shape before running larger aggregations.
SELECT *
FROM sales
LIMIT 20;Then filter, sort, or select only the columns that matter for your analysis.
SELECT order_date, region, revenue
FROM sales
WHERE revenue > 1000
ORDER BY revenue DESC;Aggregate CSV rows
SQL is especially useful when you want totals by category, region, month, customer segment, or another repeated value in the CSV file.
SELECT
region,
COUNT(*) AS order_count,
SUM(revenue) AS total_revenue,
AVG(revenue) AS average_revenue
FROM sales
GROUP BY region
ORDER BY total_revenue DESC;Join multiple CSV files
Add more than one CSV when your analysis needs lookup data, product names, account metadata, or another table that connects through a shared key.
SELECT
orders.order_id,
customers.customer_name,
orders.revenue
FROM orders
JOIN customers
ON orders.customer_id = customers.customer_id
ORDER BY orders.revenue DESC;Keep results local and export only what you need
SQL for Files runs the CSV import and query execution in your browser with DuckDB WASM. The app does not upload your files, SQL, or result rows to a backend service.
After a query finishes, use CSV export for the result set, or save the local database in your browser if you want to keep working across sessions.
Continue in the editor
Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.
Open editorRelated Learn SQL lessons
Related guides
Practical SQL Examples for CSV, JSON, and Parquet Files
A compact collection of SQL patterns you can adapt for local file analysis in SQL for Files.
Private Local Data Analysis in the Browser
Understand the local processing model behind SQL for Files and how to work safely with sensitive CSV, JSON, and Parquet files.
What Is DuckDB WASM and Why Use It for Browser SQL?
DuckDB WASM brings an analytical SQL engine into the browser, enabling local file analysis without a server-side database.