We have our data sitting on another sheet named “Data” starting in cell A1.
The syntax for the QUERY function is as follows:
Pointing to the Data
Our first argument is the source of the data. We can select the exact range that our data occupies…
…but this would not allow for the inclusion of additional data. Instead, we will select the full columns.
Forming the Query
This is the part where you use the above-mentioned clauses. The query’s clauses must be enclosed within clauses.
Our first query will select everything. “Everything” can be represented by an asterisk (*).
=QUERY(Data!A:E, “select *”,
Identifying the Header Row(s)
The final argument defines how many rows (starting with the first row) in the data make up the header row(s).
If this argument is omitted or set to -1, the headers will be guessed based on the content.
As our data has but a single header row, we will ensure the QUERY function doesn’t make an incorrect determination about our headings. We’ll use a “1” for this argument.
=QUERY(Data!A:E, “select *”, 1)
The result is a return of all columns and all rows of data from the data source.
If we want to extract specific columns from data in the same workbook, we need to identify the needed columns by column letter (ex: A, B, C).
If you are using the QUERY function within the IMPORTRANGE function to import data from a different workbook, we need to identify the needed columns by column numbers (ex: Col1, Col2, Col3).
We can get creative by placing the column identifiers in our desired order, this way we are not bound by the order of columns in the source data.
=QUERY(Data!A:E, “select A, C, B, E”, 1)