How to Use the Label Clause using Query function

The "label" clause in the Query function in Google Sheets allows you to modify the column names displayed in the query result. By using the "label" clause, you can rename the headers of the columns in the output.

Here's how you can use the "label" clause in the Query function:

  1. Start by writing the Query function: =QUERY(data, query)
  2. In the query parameter, write your query in SQL-like syntax.
  3. After your query, add the "label" clause followed by the current column name and the new column name enclosed in single quotes and separated by a comma: label current_column_name 'new_column_name'
  4. If you want to change multiple column names, separate the "label" clauses with a comma: label current_column_name1 'new_column_name1', current_column_name2 'new_column_name2'

Note that the column names should be written in the same format as they appear in the query output.

Example

Let's assume we have the following data in cells A1 to B5:

Name Age
John Smith 32
Jane Doe 28
Bob Brown 45
Alice Green 25

To use the "label" clause to change the column names, follow these steps:

  1. Start by writing the Query function: =QUERY(A1:B5, "SELECT * ")
  2. Add the "label" clause to change the column names: =QUERY(A1:B5, "SELECT * label A 'Full Name', B 'Age in Years'")

The final formula will look like this:

=QUERY(A1:B5, "SELECT * label A 'Full Name', B 'Age in Years'")

The result will be:

Full Name Age in Years
John Smith 32
Jane Doe 28
Bob Brown 45
Alice Green 25
Did you find this useful?