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.
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:
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
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
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