In this article:

SQL on Google Sheets? How?

>Click here to Import a MYSQL Database to a Lido Spreadsheet

How Google Query Language works


The Google Query Language (Google QL) is Google’s own implementation of SQL. It can be used as a command inside the QUERY function. The QUERY function has the following syntax:


QUERY(data, query, [headers])


In this function, data is the range of cells where the query command will be performed, query is the query we will send to be processed, enclosed in double quotation marks, and [headers] is an optional command to identify how many header rows are in the sheet. 


Basically, the QUERY function is created so that you can use the Google QL, which is Google’s own form of SQL, on the data stored in the sheets. Therefore, Google QL can only read the data in the database, but it cannot  modify the data.


Taking note of how the Google QL works, the following sections will focus on the SQL commands present as well as those that do not explicitly exist but can be replicated. 

SQL commands not present in Google Sheets 


As stated in the previous section, the Google QL can read the data in the database but not modify the data stored in the database. Therefore, the following SQL commands have no equivalent in Google Sheets:


  • Insert Into
  • Insert Into Select
  • Update
  • Delete


SQL commands present in Google Sheets


The following commands are present in Google Sheets, though might come with a different command name:


SQL: Select, Select Into 

Google QL: SELECT works like SELECT INTO. Data & Analytics How to Select Multiple Columns through SQL Query in Google Sheets 


SQL: Where

Google QL: WHERE. How to Use Basic SQL Commands + Query Another Sheet in Google Sheets 


SQL: And, Or, Not

Google QL: AND, OR, NOT. Data & Analytics How to Use SQL Query with Multiple Criteria in Google Sheets


SQL: Order By

Google QL: ORDER BY. How to Use Basic SQL Commands + Query Another Sheet in Google Sheets


SQL: Group By

Google QL: GROUP BY. Data & Analytics How to Use the 'Group by' SQL Clause in Google Sheets 


SQL: Select Top/Limit/Fetch First

Google QL: LIMIT. How to Use the SQL Limit and Offset Clause in Google Sheets 


SQL: Min, Max

Google QL: MIN, MAX. How to Use SQL Query for Aggregate Values in Google Sheets 


SQL: Count, Avg, Sum

Google QL: COUNT, AVG, SUM. How to Use SQL Query for Aggregate Values in Google Sheets 


SQL: Like (and the wildcards used in searching for strings in SQL)

Google QL: LIKE. How to Use SQL Queries to Search for Specific Words in Google Sheets 


SQL: As

Google QL: LABEL. How to Use SQL Labels in Google Sheets


SQL: Date, Datetime

Google QL: DATE, DATETIME. Working with Date and Time in SQL in Google Sheets 


SQL commands with equivalent separate function in Google Sheets


The following SQL commands are not present as a Google QL command but can be implemented either as a function or through other syntax:


SQL: Select Distinct

Google QL: UNIQUE function. 


SQL: Between

Google QL: As the command checks for the entries that have a value between an upper and lower limit, a similar construction can work. For an example, we want to list entries whose values in column C are between 10 and 20:


select * where C>10 and C<20


SQL: Join

Google QL: A combination of VLOOKUP and other functions can mimic the Join command in SQL. Click here for our tutorial

Google QL commands not present in SQL



There are commands present in Google QL that are either not present in SQL or serve as a specialized command for representing certain syntax in SQL:


PIVOT sorts the unique values in a column to its own individual columns and summarizes them, similar to a Google Sheets Pivot Table. Learn more here: Data & Analytics How to Use the SQL Pivot Clause in Google Sheets


FORMAT modifies how the data is displayed when copied to the destination sheet. Learn more here:  How to Use SQL Queries to Format Google Sheets


STARTS WITH lets you search for rows where its value in a specific column starts with the given string, but the total value of the cell could be longer than the given string. ENDS WITH is a similar command but is used when you know the last few characters of a string. MATCHES and CONTAINS are shorthand ways to filter rows where its value in a specific column equals a given string or contains the given string. They are alternative ways of writing column_name=”value”. You can check the examples of these three commands here: How to Use Basic SQL Commands + Query Another Sheet in Google Sheets


OFFSET lets you skip the first few entries, copying first the entries somewhere on the middle of the sheet. You can check the examples here: How to Use the SQL Limit and Offset Clause in Google Sheets 



Schedule a free automation consult
Learn more

Automate repetitive tasks with Lido

Save hours on repetitive and tedious work. Lido is a new spreadsheet that connects your spreadsheets, forms, PDFs, and email inbox.

Trigger
Action
Select trigger
When a cell value in Google Sheets changes
Check Google Sheets for today's date
When a new row is added to Google Sheets
On new Google Form submission
Send me a daily reminder
On new Typeform submission
When a cell value in database changes
Check database for today's date
When a new row is added in database
When a new HubSpot customer is created
Select action
ADDCALENDAREVENT
Creates a one- or multiple-day calendar event with optional attendees
ADDHUBSPOT
Adds an object to Hubspot
ADDSLACKCHANNEL
Create a Slack channel, and optionally add a topic or members
CALLURL
Makes any HTTP request
CREATEGOOGLEDOC
Replaces [@column_name] values in a Google Doc with the corresponding table row's values
CREATEPDF
Replaces [@column_name] values in a Google Doc with the corresponding table row's values, then export it as a PDF
FETCH
Makes any HTTP request and returns the response
INSERTROWS
Inserts given array below defined values in given worksheet
SENDGMAIL
Sends an email using your Google account
SENDOUTLOOK
Sends an email using your Microsoft Outlook account
SENDSLACK
Sends a Slack message
SENDSMS
Sends an SMS message using your Twilio account
UPDATECELL
Updates cells with given values
UPDATEHUBSPOT
Updates a property of a Hubspot object
Trigger is required
Action is required
Get started