October 10, 2020

How to Select Multiple Columns through SQL Query in Google Sheets 

Chart with arrows pointing up and down
SECTIONS
  1. How to Select Multiple Columns through SQL Query in Google Sheets 
  2. Limitations & An Alternative Method...

Querying only becomes effective if we see the associated information in our query results. This is possible if we can select multiple columns through SQL queries.

Is it possible in Google Sheets? Yes!

This tutorial will tackle how it is done via the QUERY function and its associated SQL in Google Sheets.

How to Select Multiple Columns Using SQL Query

When you want to list down multiple columns for each entry but apply a single criterion applied to one column, you simply list down the columns to select then followed by the condition.  For our example, we have added a table containing U.S. states’ etymology on one sheet.

U.S. state names etymology sheet. Data from Wikipedia article on U.S. state names etymology.
U.S. state names etymology sheet. Data from Wikipedia article on U.S. state names etymology!


What if we want to display the state name column and the language of origin column in a separate sheet, without any criterion to use? We use the following query:

select A, D

With this, we'll have to place it in Google Sheets' QUERY function with the format:

=query([range],"[SQL query]'")

And we get the following result:

Query result listing the states and the language of origin of their names. 
Query result listing the states and the language of origin of their names. 

The same syntax will work if you add conditions to the query. For example, we wish to filter our initial results by adding the column for the year the name was first attested and by selecting states whose names were first attested before 1800. Our query will now look like this:

select A, C, D where C < 1800

With this, we'll have to place it in Google Sheets' QUERY function with the format:

=query([range],"[SQL query]'")

And our result will look like this:

Query result listing the states, the year their name was first attested, and language of origin of their names. All the listed states have their name first attested before 1800.
Query result listing the states, the year their name was first attested, and language of origin of their names. All the listed states have their name first attested before 1800.


You would naturally ask whether two or more criteria can be combined in a single query. The answer is yes! You can read more about it here.

Can we change the order the selected columns appear? Absolutely! Just arrange the column list in your preferred order. If we make the following query:

select D, C, A 

With this, we'll have to place it in Google Sheets' QUERY function with the format:

=query([range],"[SQL query]'")

The result will look like this: 

Query result listing the states, the year their name was first attested, and language of origin of their names. The order however was flipped: the language of origin of their names came first, then the year first attested, and finally the state name.
Query result listing the states, the year their name was first attested, and language of origin of their names. The order however was flipped: the language of origin of their names came first, then the year first attested, and finally the state name.

Limitations & An Alternative Method...

A complex combination of multiple columns and criteria is needed to get refined search results, but even then, you still have to read the entries one-by-one to get meaningful analysis, to ultimately make great decisions for your business.

I have one suggestion for you to do so without having to do the laborious job of querying large databases: consider trying Lido. With a few clicks on your laptop, you can now access all the relevant metrics without going through the hassle of accessing the SQL databases of your eCommerce platforms and then coding the formulas to process them. Let our platform do it all for you!

Suscribe to get more data and analytics tips!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.