Google Sheets QUERY: Selecting Columns
SELECT
A simple query starts with the keyword SELECT followed by the data to be returned.
Example of use
The goal for this first example will be to select the entire database using the QUERY function.
Enter into the QUERY function:
- data: the data range =>
DB!A1:G15
- query: the query to execute =>
"SELECT *"
(the * means "all columns") - headers: the number of header lines (usually 1), leave blank to automatically determine the number of header lines based on the data
The following formula does indeed return the entire database:
=QUERY(DB!A1:G15,"SELECT *",1)
In this case =QUERY(DB!A1:G15,"SELECT *",1)
returns the same result as if the "headers" argument had not been entered (and therefore automatically calculated by the function) =QUERY(DB!A1:G15,"SELECT *")
.
To simplify the formulas of the following examples, the "headers" value will not be entered (although it is preferable to do so when you use this function).
Selecting 1 column
To select a single column, enter the letter of the column after SELECT:
=QUERY(DB!A1:G15,"SELECT C")
Selecting multiple columns
To select multiple columns, enter the letter of each column separated by a comma:
=QUERY(DB!A1:G15,"SELECT A, C, E")