Converter tool

SQL Query for CSV and Excel

Load CSV and XLSX files as tables, then query them with SQL: joins, GROUP BY, sub-selects and more. Runs in your browser, so the files never upload anywhere.

Step 1

Tables

No tables yet.

Step 2

Query

Load at least one file (or the sample tables) to start writing queries.

Ctrl or Cmd + Enter also runs it.
What the query box allows
  • One SELECT at a time, optionally starting with WITH ... AS. JOIN, UNION, GROUP BY, HAVING, ORDER BY, LIMIT, CASE and sub-selects work.
  • Tables are read-only. INSERT, UPDATE, DELETE, DROP, CREATE, ATTACH, LOAD, REQUIRE, INTO and file or URL sources such as CSV('...') are blocked.
  • Table names are lower-case and case sensitive. Put column names with spaces or odd characters in [square brackets]. If an alias such as total is rejected, write it as [total].
  • Empty cells are NULL. Number, date (as YYYY-MM-DD text) and yes/no columns are converted by their detected type.
  • A long query can freeze this tab for a moment because it runs on the page itself.

Step 3

Result

Run a query to see its rows here.

SQL Query for CSV and Excel Files

Operator: Abdulla Al Fahad. How tools are built and checked

Spreadsheet formulas get awkward the moment a question involves two files: which customers have no orders, what each tier spent, which month had the most refunds. In SQL each of those is one short query. This page gives you that without a database to install. You add CSV or XLSX files, each becomes a table, and you type a SELECT.

The engine is alasql, an in-memory SQL library that runs inside this tab. Your rows are never sent anywhere, which matters when the files hold customers, payroll or anything under an NDA. The query box is deliberately narrower than alasql itself: it takes one read-only SELECT, and anything that could read a file or URL, write somewhere or run script is refused before it reaches the engine.

Key features

  • Several files at once, each as its own table, with a schema list showing row counts, column names and detected types
  • Click a table or column name to insert it into the query; column names with spaces are inserted in brackets
  • Example queries built from your own tables: preview, counts and totals by a category column, top rows, rows above the average, monthly totals, and a join when two tables share a column name
  • Joins (INNER, LEFT, RIGHT, FULL OUTER, CROSS), UNION, GROUP BY, HAVING, ORDER BY, LIMIT and OFFSET, CASE, LIKE, IN, BETWEEN, sub-selects and WITH ... AS
  • String, number and date functions such as UPPER, SUBSTRING, ROUND, COALESCE, YEAR, MONTH, DATEDIFF, plus aggregates SUM, AVG, MIN, MAX, COUNT, MEDIAN, STDEV and GROUP_CONCAT
  • Ctrl or Cmd plus Enter to run, run time and row count shown, plain-language error messages
  • Download the result as CSV, XLSX or JSON

Tables, column types and what the SQL box accepts

Input is .csv, .tsv, .txt or .xlsx, up to 25 MB per file. CSV text is read as UTF-8 (UTF-16 with a byte-order mark also works) and quoted fields with commas or line breaks stay intact. For XLSX only the first worksheet is used. At most 300,000 rows are read from a single file, the tables together may hold 200,000 rows, and you can have 12 tables at a time; a file that would break a limit is skipped with a message naming it.

Table names come from the file name: lower-cased, accents removed, anything that is not a letter, digit or underscore turned into an underscore. Sales Data (2024).csv becomes sales_data_2024, 2024.csv becomes t_2024, and a name that is an SQL word, such as order.csv, gets _data added (order_data). Two files that would collide become orders and orders_2. Column names are kept exactly as in the header row, so a column called Order Date is written [Order Date] in a query. Table names are case sensitive: ORDERS will not find orders, and the error says so.

Cells are converted per column so SQL behaves the way you expect. A column is called a number column when at least 90 percent of its first 500 non-empty cells are numbers; values such as 1,200, $5.50 and (1,250.00) are read as 1200, 5.5 and -1250. A date column is stored as YYYY-MM-DD text, which sorts correctly and works with YEAR(), MONTH() and SUBSTRING(); day-first or month-first slash dates are decided by looking for a value that can only be one of them, and month-first is the default when nothing settles it. Columns full of true, false, yes or no become booleans. Empty cells are NULL. A cell that does not fit its column's type, say the word TBD in a number column, stays as text, which is why SUM over such a column can behave oddly; the schema list shows each column's detected type and you can spot the problem there.

Results show in a paged grid. The grid itself holds the first 100,000 rows of a result, with a warning once a result passes 200,000 rows, while the CSV, XLSX and JSON downloads contain every row. XLSX stops at Excel's own limit of 1,048,575 data rows. Dates and other non-plain values are written as ISO text; NULL stays empty in CSV and XLSX and null in JSON.

How it works

When you press Run, alasql loads on first use (it is a separate download, not part of the page), a fresh private database is created and your tables are attached to it. The query runs against those in-memory rows, and the database is thrown away afterwards, so nothing carries over between runs.

Before the engine sees the query, a checker parses it with alasql's own parser and walks the whole syntax tree. It accepts exactly one statement, and that statement must be a SELECT or a WITH ... SELECT. Every FROM and JOIN source must be a table you loaded, a CTE name or a sub-select. Every function, aggregate and operator must be on a fixed list, and the syntax that alasql uses for parameters, variables, JSON literals, window functions and embedded JavaScript is refused. A text scan that ignores quoted strings runs first and catches INTO and the data-source functions (CSV, XLSX, JSON, FILE, HTML and others) wherever they appear, so tricks such as comments or bracketed names do not slip through.

Tables are plain arrays of rows, and a SELECT does not change them. If a query is slow, the tab is busy until it finishes, because the engine runs on the page rather than in a background worker; there is no cancel button for that reason.

Common use cases

  • Finding which rows of an order export have no matching customer record before importing both into a CRM
  • Totalling a ledger export by month and category, then handing the finance team an XLSX of the result
  • Comparing two inventory snapshots with a LEFT JOIN to list SKUs that appear in one file but not the other
  • De-duplicating a mailing list with GROUP BY email HAVING COUNT(*) > 1 to see which addresses repeat and how often
  • Checking a survey or log export during development without loading it into SQLite or Postgres first

How to use this tool

  1. Choose one or more CSV or XLSX files, or press Load sample tables to try it.
  2. Check the schema list: the table names to use, and whether each column was detected as number, date, boolean or text.
  3. Type a SELECT in the query box, or press one of the example buttons and edit it.
  4. Press Run query, or Ctrl or Cmd plus Enter.
  5. Page through the result grid, then download CSV, XLSX or JSON.

Example

Sample tables: orders (12 rows) and customers (7 rows), sharing customer_id

SELECT t2.tier,
  COUNT(*) AS orders_n,
  ROUND(SUM(t1.amount), 2) AS revenue
FROM orders t1
JOIN customers t2 ON t1.customer_id = t2.customer_id
GROUP BY t2.tier
ORDER BY revenue DESC

Result: 3 rows

tier    orders_n  revenue
bronze         3  1549.1
gold           5  762.04
silver         3  350.75

Order 1012 (customer 7, 720.00) is not here: customer 7 is missing from customers, and an inner join drops it. Replace JOIN with LEFT JOIN and WHERE t2.customer_id IS NULL to list such orders.

Tips for best results

  • Alias every column in a join with a name you choose. SELECT * across two tables returns objects keyed by column name, so two columns called id collapse into one.
  • Put a column with a space or punctuation in square brackets, and also an alias that is an SQL word. AS total and AS count fail to parse, while AS [total] and AS revenue work.
  • Use SUBSTRING([date_column], 1, 7) to group by month and SUBSTRING(..., 1, 4) to group by year; dates are YYYY-MM-DD text, so this is exact.
  • Compare text and numbers carefully: a column detected as text compares '10' and '9' as strings, so '9' sorts after '10'. Check the schema list and, if a numeric column came through as text, look for stray characters in its cells.
  • Add LIMIT while you work out a query. A join between two large tables without a good ON clause can produce millions of combinations and freeze the tab.

Common pitfalls

Only one SELECT runs at a time. A second statement after a semicolon is refused, and a semicolon inside a quoted string also trips alasql's parser; use CHAR(59) if you need one in text.

Window functions (OVER, ROW_NUMBER, RANK) are not supported, and the checker rejects them rather than returning odd columns. Use a sub-select with a count, or GROUP BY, to get the same answer.

Table and column names are case sensitive, and a few ordinary words are reserved in alasql. If an unexpected syntax error points at a column or alias, wrap it in [brackets].

The tool is read-only by design. INSERT, UPDATE, DELETE, DROP, CREATE, ATTACH, LOAD, REQUIRE, USE, SET, SELECT ... INTO, parameters such as ? and @name, JavaScript, JSON literals and file or URL functions (FROM CSV('...'), XLSX, JSON, FILE, HTML) are all refused, which also means the page can never fetch a URL for you.

Only the first worksheet of an XLSX is loaded, and formulas are read as their last saved value. If the data lives on another sheet, save that sheet as CSV or move it first.

Best practices

  • Look at the detected types in the schema list before writing queries, and fix mixed columns in the source file instead of fighting them in SQL.
  • Keep file names short and descriptive: they become the table names you will type many times.
  • Download XLSX or CSV of anything you will share, and keep the SQL text beside it so the answer can be reproduced.

Reading alasql errors

Syntax errors name the position where the parser gave up and show a caret, so look just before it: a missing comma, an unquoted column with a space, or an alias that is an SQL word. Errors that start with There is no table called name list the tables that are loaded, and Table names are case sensitive points out when only the capital letters differ.

Messages that begin with Tables are read-only, Loading files or URLs is blocked or Parameters, variables, JavaScript... mean the checker refused the query. They never mean something partly ran: a refused query is not passed to the engine at all.

What stays on your computer

File contents, table data, queries and results live in memory in this tab. There is no upload, no query log and no account. The alasql library itself is downloaded from this site the first time you run a query, and that request carries nothing from your files. Closing or reloading the tab clears everything, so keep a copy of any query you want to reuse.

Frequently asked questions

Can I update or delete rows with SQL here?

No. The tables are read-only, so INSERT, UPDATE, DELETE, DROP and CREATE are refused. To change data, query what you want to keep and download the result as a new file.

Why did my SUM come back as text or look wrong?

A column is treated as numbers only when 90 percent or more of its first 500 non-empty cells parse as numbers. If a column came through as text, the schema list shows text next to it. Find the cells that are not numbers, such as N/A or TBD, and clean them in the file.

Is it the same SQL as MySQL or PostgreSQL?

It is alasql's dialect, which resembles standard SQL with some T-SQL and MySQL habits. Common SELECT syntax works, but functions differ: use SUBSTRING and YEAR rather than DATE_TRUNC or STRFTIME, and note that window functions are not available.

Why can't I load a file with FROM CSV('file.csv') inside the query?

Those data-source functions can read files and web addresses, so they are blocked. Use the file picker above the query box instead; it hands the file to the page without any network request.