How to Run SQL Queries on Google Sheets

0 Comments
Editor Ratings:
User Ratings:
[Total: 1 Average: 2]




This post explains how to run SQL queries on Google Sheets. Here I will talk about a Google Apps Script project which you can use in your Google Sheet to manipulate data in it. Basically there is a whole SQL engine that you can add in Google Sheet and use that. You can use SQL with a formula or it adds a prompt in Google Sheet to execute queries. You can execute simple as well as advanced SQL queries and get the result. If there are a lot of sheets in your spreadsheet then you can selectively fetch data from them and save it anywhere you like.

SheetSQL is an open source project and there is a demo for it as well. You can clone it in your Google Account and then start creating Google Sheets. The Sheets you create with this will have SQL functionality in them. You can then easily use SQL command to retrieve data and then do whatever you want. From simple SELECT statements to complicated aggregate functions based queries, you can build them all and execute them. You can use SQL in any sheet and in any cell.

How to Run SQL Queries on Google Sheets?

Adding the SQL engine to a Google Sheet is very simple. You just copy this Google Sheet in your account and it has SQL engine enabled. After you copy it to your account, you can test the SQL. There are some sub sheets in this spreadsheet and you can treat them like tables in your SQL commands. There is an introduction page as well that you can use to read some basics about it.

Now, to text it, you can turn to any blank sheet and then use two methods of executing the SQL queries. The first method is very simple. Here you just select the cell where you want to see the output data. After that, use the SQL tab in the sheet to select the “Show prompt” option. Next, you enter the SQL query and then see its output simple as that.

Google Sheet query via prompt

Another method of using SQL queries is though cell formula. You can add the =SQL(“statement”) for the cells and then enter the SQL query. It will get the result there and you can then copy the data or do whatever you want to do.

SQL statements by formula

Form now on, you will have to create the new Sheet by replicating this sheet. The new sheets which will be created will have the SQL functionality and you can execute SQL queries with aggregate function such as AVG, MAX, MIN, SUM, etc. You can see the examples below.

SheetSQL aggregate fucntions

This is how you use SQL queries in Google Sheets. You just use this simple SQL engine by just replicating the Google Sheet. Or, if you have some knowledge of Google Apps Script then you can manually add script by copy paste. All the scripts which make this SQL engine are stored in this GitHub repository. Even though, it is quite old but still works like charm.

Similar posts:

Closing words

SQLSheet is an amazing SQL engine for Google Sheets to run SQL queries. You can use it to manipulate data from different inner sheets and then store the result. Almost all kind of SQL queries are supported. You can execute some basic queries as well use some complex ones that deal with grouping and calculations. So, if you are looking for ways to add SQL functionality in Google Sheets then this post is all you need to get started.

Editor Ratings:
User Ratings:
[Total: 1 Average: 2]
Free/Paid: Free

Leave A Reply

 

Get 100 GB FREE

Provide details to get this offer