Run SQL Queries on your Spreadsheet Data
There are 2 instances when you would want to run SQL queries on your Spreadsheet data
- You know SQL and doing your Data Analysis using SQL would be faster
- You want to learn SQL and need to practice on some real data
In this article we highlight two methods on how to run SQL queries on your spreadsheet data.
Easy way, but could be a a bit limited based on your use case
We at Love Spreadsheets, built a FREE tool that lets you upload up to 3 Excel files and run SQL queries on that data
You can check it out here: https://apispreadsheets.com/sql
It is very simple to use.
Step 1: Upload your files
You can upload a maximum of 3 files at a time. These can be .xls, .xlsx, or .csv files.
The first line of the files will be read as the column names.
After the files have been uploaded successfully you will be able to view their data and their identifier in the space below the query input
Step 2: Write your SQL Query
Now you can write your SQL query to run on your spreadsheet data
The table names would be file1, file2 or file3 based on how they were uploaded
The column names would be present on the header of the data that you see
Using these table and column names, you can write your SQL query like the following
SELECT file1.Title, file1."Runtime (Minutes)", file2.Rating
FROM file1, file2
WHERE file1.Genre LIKE '%Drama%'
AND file2.Metascore IS NOT NULL
AND file1.Title=file2.Title
ORDER BY file1.Title;
As you can see in the query, column names that have spaces require double quotes
Step 3: Run your SQL Query
Click on the Run Query button to run the SQL Query
Step 4: View & Download your results
After you run your SQL query, your results will be visible in a table underneath
You will also be able to download your results in an Excel file by clicking the Download Query Results link
Harder way(s), but can be adapted extensively to your needs
There are a few ways to run SQL queries on your spreadsheet data without a dedicated solution.
The full walk through is a bit out of scope for this article, but we will link to other articles that describe the steps in more detail.
Prerequisite
- Python
- Basic library install experience
Option 1: Create a Database & Run SQL Queries on it
- Create a SQLite database on your computer
- Import your spreadsheet data to SQLite tables
- Run SQL queries on your SQLite database
This options requires you to be familiar with your computer’s terminal or command line for creating the database for step 1.
It also requires knowledge of Python to insert your spreadsheet data into the database for step 2.
Once step 1 and step 2 are complete, step 3 requires you to install a software to use to run SQL queries.
Option 2: Use Python to read data & DuckDB to run queries
- Read your spreadsheet data into Python
- Run SQL queries using DuckDB library within the Python script
This option is what makes up the backbone of our API Spreadsheets SQL tool’s back-end
Unlike the option above, this process only requires knowledge of Python
Parting thoughts
Running SQL queries on your spreadsheet data can either be
- An easy way to do data wrangling with a tool (SQL) that you already know
- Learn SQL by practicing queries on real data