Home › Developer Tools › Query CSV with SQL

Query CSV with SQL

Open one or more CSV, Excel, JSON or Parquet files and query them with real SQL: filter, group, join files together, use window functions, then export the result. Everything runs in your browser with DuckDB-WASM, so your data never leaves your computer.

Last updated:

Engine: not loaded
Ctrl + Enter to run
Advertisement
Advertisement

How to use the Query CSV with SQL

  1. Add your files with Add files or by dropping them on the page. Each file becomes a table named after the file; Excel workbooks create one table per sheet.
  2. Check the schema in the sidebar: table names, columns and detected types. Click a table to preview it.
  3. Write your SQL in the editor or start from an example, e.g. SELECT country, COUNT(*) FROM customers GROUP BY country.
  4. Run the query with the Run query button or Ctrl+Enter (Cmd+Enter on Mac). The first run loads the SQL engine once (a few MB).
  5. Export the result as CSV, JSON or Excel, or copy it to paste into another tool.

Supported files and how they become tables

FileRead withNotes
.csv, .tsv, .txtread_csv_autoDelimiter, quoting, header and column types are detected automatically.
.xlsx, .xlsmBuilt-in reader, then read_csv_autoOne table per sheet; the first row is used as column names.
.json, .ndjson, .jsonlread_json_autoAn array of objects or one object per line; nested objects become STRUCT columns.
.parquetread_parquetColumnar and typed, so it loads fastest and keeps exact types.

Handy DuckDB SQL for CSV files

TaskSQL
Profile every column (min, max, nulls, distinct)SUMMARIZE sales;
All columns except someSELECT * EXCLUDE (notes, internal_id) FROM sales;
Group by every non-aggregated columnSELECT region, product, SUM(amount) FROM sales GROUP BY ALL;
Top row per groupSELECT * FROM sales QUALIFY ROW_NUMBER() OVER (PARTITION BY region ORDER BY amount DESC) = 1;
Parse European datesSELECT strptime(day, '%d/%m/%Y')::DATE AS day FROM sales;
Month from a dateSELECT date_trunc('month', order_date) AS month, COUNT(*) FROM orders GROUP BY 1;
Pivot rows into columnsPIVOT sales ON region USING SUM(amount) GROUP BY product;
Stack two files with the same columnsSELECT * FROM jan UNION ALL BY NAME SELECT * FROM feb;
Text search (case-insensitive)SELECT * FROM customers WHERE name ILIKE '%smith%';

Tips

  • Quote odd column names with double quotes: SELECT "Order Date", "Unit Price ($)" FROM sales. String values use single quotes.
  • Create helper tables with CREATE TABLE big_orders AS SELECT …; they appear in the sidebar and can be queried like files.
  • Multiple statements separated by semicolons run in order; the result of the last one is shown.
  • To explore an existing database file instead of flat files, use the SQLite Viewer. To tidy up a long query, try the SQL Formatter.

Frequently asked questions

Can I really run SQL on a CSV file without a database?

Yes. DuckDB-WASM is a complete analytical database compiled to WebAssembly that runs inside your browser tab. Each file you add is loaded into an in-memory table, so you can use standard SQL with no installation, server or account.

Are my files uploaded anywhere?

No. Files are read locally by your browser and processed by DuckDB inside the page. Only the SQL engine itself is downloaded from a public CDN the first time you run a query; your data is never sent.

How are table names chosen?

The file name is lower-cased and anything that isn't a letter, digit or underscore becomes an underscore: Sales Report 2025.csv becomes sales_report_2025. Excel files get one table per sheet, such as budget_q1. Names are shown in the sidebar and you can quote them with double quotes.

How do I join two CSV files?

Add both files, then use a normal join on the shared column: SELECT * FROM orders o JOIN customers c ON o.customer_id = c.customer_id. With identical column names you can also write JOIN customers USING (customer_id).

Which SQL dialect is used?

DuckDB's SQL, which is close to PostgreSQL. Besides standard SQL it supports handy extras such as SELECT * EXCLUDE (col), GROUP BY ALL, QUALIFY for filtering window functions, PIVOT, and functions like strftime, regexp_matches and list_aggregate.

How large can my files be?

It depends on your device's memory. Files of a few hundred MB usually work in desktop browsers, and Parquet is much more compact than CSV. Results are shown up to 1,000 rows on screen, while exports include every row.

Why are some columns detected as text?

DuckDB samples the file to guess each column's type. Mixed values such as numbers with units or inconsistent date formats are kept as VARCHAR. Convert them in the query, for example CAST(price AS DOUBLE) or strptime(day, '%d/%m/%Y').

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.Compare Excel FilesCompare two Excel spreadsheets cell by cell, highlight changes and export a diff report.Cohort Retention Table GeneratorTurn signup and activity data or cohort counts into a cohort retention heatmap and export it.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.PX to EM ConverterConvert pixels to em using the parent font size, and em back to px, with conversion tables.Query String to JSONConvert URL query strings to JSON with nested brackets and arrays, and JSON back to a query string.REM to PX ConverterConvert CSS rem values to pixels for any root font size, with a quick 0.25–6rem table.SQL to JSON ConverterConvert SQL INSERT statements and dumps into a JSON array of row objects, with CSV export.TSV to CSV ConverterConvert TSV to CSV and back, or between tab, comma, semicolon and pipe, with correct quoting.TypeScript to JavaScriptConvert TypeScript or TSX to clean JavaScript instantly: strip types, keep or compile JSX.XML to YAML ConverterConvert XML to clean YAML with attributes, text nodes, lists and exact error lines.YAML to XML ConverterConvert YAML to pretty, well-formed XML with custom root, attributes and array item tags.Boolean Algebra SimplifierSimplify boolean expressions or minterm lists to minimal SOP and POS with Quine-McCluskey steps.CSV CleanerClean messy CSV in one click: trim spaces, drop empty rows and columns, fix headers, dedupe.CSV VLOOKUP ToolJoin two CSV or Excel files on a key column like VLOOKUP, with left, inner and full joins.Remove Duplicates in ExcelFind and remove or highlight duplicate rows in XLSX or CSV files by the columns you choose.GeoJSON ViewerView GeoJSON on a map, inspect and edit properties, validate against RFC 7946 and export.GPX ViewerOpen GPX tracks on a map with distance, elevation profile, moving time, speed and splits.JSON Repair ToolFix broken JSON automatically: trailing commas, quotes, comments, truncated data, with a diff.Karnaugh Map SolverSolve 2–6 variable K-maps: click cells or enter minterms to get the minimal SOP or POS with groups.Merge Excel FilesCombine XLSX, XLS and CSV files into one workbook or append all rows into a single sheet.Parquet File ViewerOpen Apache Parquet files in your browser: schema, rows, filters and CSV or JSON export.Online Serial MonitorTalk to Arduino, ESP32 and USB serial devices in your browser: log, send, plot and save.Split Excel FileSplit an Excel sheet into several files by row count or by each value in a column, as ZIP.SQL Create Table GeneratorDefine columns, keys, defaults and indexes; get CREATE TABLE SQL for MySQL, Postgres and more.SQL IN Clause GeneratorTurn a pasted list into a SQL IN ('a','b') clause with quoting, dedupe and 1,000-item chunks.SQL Online CompilerRun SQL queries online on SQLite with sample databases, a result grid, CSV export and .db save.SQL to ER DiagramPaste CREATE TABLE statements and get an entity-relationship diagram with keys and links.XML to XSD GeneratorGenerate an XML Schema (XSD) from sample XML: types, occurrences, attributes and namespaces.XML ValidatorCheck if XML is well-formed, see the exact line and column of each error and pretty-print it.Wildcard Mask CalculatorConvert a subnet mask or CIDR to a wildcard mask for ACLs and OSPF, with range and binary.CSV to VCF ConverterConvert a contacts CSV into a vCard (.vcf) file, mapping columns to name, phone, email and more.CSV to YAML ConverterConvert CSV rows to a YAML list of mappings with type inference and delimiter detection.Endianness ConverterSwap byte order of 16, 32 and 64-bit hex values and see big- and little-endian integers and floats.
See all 129 Data & File Format Converters →