In this article:

How to Use SQL Labels in Google Sheets

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

One SQL function that we can use to further improve our data analysis is the label clause. The label clause is used to, well, add a label on a column of data. The query follows the following format:

label column1_id “label_name1”, column2_id “label_name2”

... And so on, separating each pair by a comma. 

Add column header using label clause

We can use the label clause to add column headers to the data without modifying the original sheet. For example, if we have this source data:

snippet of the source sheet. There is no column header.
Snippet of the source sheet. There are no column headers.


Using the following query...

label A 'State Name', B 'Year Recorded', C 'Language', D 'Original Word', E 'Notes'

... place it in Google Sheets' QUERY function with the format...

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

... we get the following result:

snippet of the output sheet. There is a column header inserted by the QUERY command.
There is now a column header inserted by the QUERY command.

Replace column header using label clause

The same query can be used to replace existing column headers in your new copy of the sheet. If we have the following sheet… 

snippet of the source sheet. There are column headers.
Again, snippet of the source sheet. This time, there are column headers.


And, we want to replace the headers with different names (from state name to state, from year first attested in original language to year, from language of origin to language, from word in original language to word, and from meaning and notes to notes), we can set the following query:

label A 'state', B 'year', C 'language', D 'word', E 'notes'

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

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

And the result looks like this:

Snippet of the output sheet. The column headers were replaced by new ones.
Snippet of the output sheet. The column headers were replaced by new ones.


Can we use the label string as a pointer in queries?

You might have noticed that we use the column letter to point to specific columns in all our queries. Unfortunately, we cannot use the label string as a pointer in writing queries

Does it feel a bit inefficient? What’s certainly more inefficient is having to spend long hours coding this when you could, instead, do it all in a couple clickec.If you want to be more efficient, 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