How to Run SQL Queries on a Spreadsheet Without a Database
Anyone who's spent time buried in a nested VLOOKUP or a nine-layer array formula has probably had the same thought: this would be a single line of SQL. Filtering rows, joining two tables, grouping and summing, SQL was built for exactly this, and spreadsheets weren't. So why do most of us still reach for spreadsheet formulas instead of SQL when the data lives in a spreadsheet?
Mostly because setting up an actual database just to query a table you already have feels like overkill. Standing up SQLite, writing an import script, keeping two copies of your data in sync, it's a lot of ceremony for a question that should take one query to answer.
The Case for Querying Sheets Directly
The idea is simple: treat each sheet tab as if it were a database table, where the header row becomes your column names, and just query it directly with SQL, no separate database, no import step, no syncing.
SELECT name, region, revenue
FROM Sheet1
WHERE revenue > 10000
ORDER BY revenue DESCIf you've ever written SQL before, this is immediately familiar. If you haven't, it's still more readable than most nested spreadsheet formulas once you get past the first few queries.
Where This Actually Helps
Filtering large datasets. Spreadsheet formulas like FILTER() or QUERY() (in Google Sheets) can technically do this, but they get unwieldy fast once you're combining multiple conditions. A WHERE clause with AND/OR stays readable no matter how complex the condition gets.
Joining data across sheets. This is where spreadsheets genuinely struggle. VLOOKUP and INDEX/MATCH can join two tables, but only clumsily, and only for simple one-to-one lookups. A real SQL JOIN handles one-to-many and many-to-many relationships the way they're supposed to be handled.
SELECT orders.id, customers.name, orders.total
FROM Orders
JOIN Customers ON Orders.customer_id = Customers.idAggregating without pivot tables. GROUP BY with SUM(), COUNT(), or AVG() gets you what a pivot table gives you, but as a query you can save, tweak, and rerun instantly, rather than rebuilding a pivot table each time your source data changes.
Tools That Actually Let You Do This
A few approaches exist if you want to try this yourself:
- Google Sheets'
QUERY()function supports a SQL-like syntax, but it's a hybrid, not real SQL, and it has real limitations around joins and syntax quirks that trip people up. - Importing into SQLite manually works, and gives you real SQL, but means keeping your spreadsheet and your database in sync by hand, which gets tedious fast for anything you update regularly.
- NativeOffice's built-in SQL-on-Sheets takes the middle path: your spreadsheet tabs are queryable as SQL tables directly, no import, no separate database file, no syncing. Write a query, get your result back as a new sheet or a live preview, and your original data never moves. It also runs fully offline, so nothing about your dataset leaves your machine to make this work.
If you're the kind of person who thinks in SELECT and WHERE before you think in cell references, querying your data directly, instead of translating your thinking into spreadsheet formula syntax, tends to be both faster and far less error-prone once your data gets past a trivial size.
Need to clean up repeated rows first? See how to remove duplicates in Excel.
