How to Query CSV and Excel Files with SQL, Step by Step
Learn to answer spreadsheet questions with SQL: filtering, grouping, totals and joins across CSV and Excel files, all in your browser without a database.

How to Query CSV and Excel Files with SQL, Step by Step
Most business data arrives as a spreadsheet export. Sales from the shop system, leads from a form, invoices from accounting. The questions people ask about those exports are database questions: how much per region, which customers bought twice, which orders have no matching invoice. SQL was designed for exactly these questions, and you do not need to install a database server to use it. The free SQL Query on CSV and Excel tool loads your files as tables in the browser and runs SELECT statements on them. This guide walks through the queries that cover most everyday needs.
Getting the data in
Drop one or more files onto the tool. A CSV becomes one table, and an Excel workbook gives one table per sheet. Table names are derived from the file name, lower case and with underscores instead of spaces, so a file called Sales 2026.csv becomes sales_2026. You can rename any table in its box. Under each table you see its columns as small buttons; clicking one inserts the name into the query, wrapped in double quotes if it contains a space.
Two details matter before you write anything. First, empty cells are treated as NULL, which is how databases represent a missing value. Second, a column is numeric only when every filled cell in it is a plain number. If a single cell says n/a, the whole column stays text, and sums will ignore it. You can still convert inside the query with NUMBER(column), which also understands thousands separators and currency signs.
Filtering rows
The simplest useful query picks rows that meet a condition. SELECT * FROM sales WHERE Region = 'North' returns all northern orders. Text values go in single quotes; column names with spaces go in double quotes. Combine conditions with AND and OR, and use parentheses when you mix them. LIKE matches patterns: Product LIKE 'Lap%' finds everything starting with Lap, and the comparison ignores letter case for ordinary letters. IN is shorter than many ORs, as in Region IN ('North', 'East'), and BETWEEN covers ranges such as Revenue BETWEEN 500 AND 1000.
Totals with GROUP BY
Grouping is where SQL beats manual pivot tables for speed. SELECT Region, COUNT(*) AS orders, SUM(Revenue) AS revenue FROM sales GROUP BY Region ORDER BY revenue DESC gives one line per region with the number of orders and their total, largest first. AVG, MIN, MAX and MEDIAN work the same way. COUNT(DISTINCT Rep) counts how many different reps appear. HAVING filters after grouping, for example HAVING SUM(Revenue) above 5000 written with the usual comparison sign, which keeps only big regions.
Dates often need grouping by month. YEARMONTH(Date) turns 2026-03-18 into 2026-03, so GROUP BY YEARMONTH(Date) gives a monthly series. YEAR, MONTH and DAY extract single parts, and they understand both ISO dates and the day/month/year style common outside the United States.
Joining two files
Joins answer questions that span files. Suppose sales.csv has a Rep column and reps.csv lists each rep with a Team. SELECT r.Team, SUM(s.Revenue) FROM sales s JOIN reps r ON s.Rep = r.Rep GROUP BY r.Team totals revenue per team. The letters s and r are aliases that keep the query short and make clear which table each column comes from.
The join type changes which rows survive. An inner JOIN keeps only rows that found a partner. LEFT JOIN keeps every sale even without a matching rep, filling the rep columns with NULL. That is the classic way to find orphans: add WHERE r.Rep IS NULL and you get the sales whose rep is missing from the list. FULL JOIN keeps unmatched rows from both sides, and RIGHT JOIN mirrors LEFT JOIN.
Building results in stages
The tool does not support subqueries, but it has a practical replacement. After running a query, press Save as table, and the result becomes a new table called result that you can query again. That makes complex questions easy to build in steps: first total by customer, save, then join the totals to the customer list.
Exporting and sharing
The result grid shows up to 500 rows, but exports include everything. CSV suits other tools, XLSX opens directly in Excel and includes your query on a second sheet so you remember how the numbers were made, and JSON is handy for developers. Copy for Excel puts tab-separated text on the clipboard for pasting into an open sheet.
Common errors and what they mean
Unknown column usually means a typo or a name with spaces that was not quoted. Table not loaded lists the names that do exist. If a join reports too many rows, the ON condition probably matches far more pairs than intended, often because the key column is mostly blank.
Limits to keep in mind
The engine reads data; it does not change your files. There is no INSERT or UPDATE, and window functions are not available. Old XLS and Parquet files need converting first. Because everything runs in memory, very large files can be slow on phones. For the everyday export, though, a few lines of SQL replace a lot of clicking.



