In this article:

How to Select Multiple Columns through SQL Query in Google Sheets

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

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!


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