How to use the QUERY function in Google Sheets
Google Sheets formula
=QUERY(A1:F13,"select B, D, F where F > 2000",1)Give QUERY a range, a query in quotes and the number of header rows: =QUERY(A1:F13,"select B, D, F where F > 2000",1) returns the rep, product and revenue of every order over $2,000.
- Result on the example
- a 6-row list that spills from H1 in
H1 - Excel
- See below
See it work
The formula is already in H1. Change any input and the result updates, or edit the formula to experiment.
How it works
The query is written in Google's query language, as text. select B, D, F picks the columns by their letters in the range, in the order you list them. where F > 2000 keeps only the rows that pass the test. The last argument, 1, tells QUERY the range has one header row, so the headers come back on top of the result.
=QUERY(A1:F13,"select B, D, F where F > 2000",1)Result{6 rows × 3 cols} "Rep", "Product", "Revenue", "Ana Ruiz", …
A1:F1313 rows × 6 cols: "Date", "Rep", "Region", "Product", …A range: 13 rows × 6 columns.
QUERY(A1:F13,"select B, D, F where F > 2000",1){6 rows × 3 cols} "Rep", "Product", "Revenue", "Ana Ruiz", …QUERY: Runs a SQL-like query: select, where, group by, order by, limit, label.- data
A1:F1313 rows × 6 cols: "Date", "Rep", "Region", "Product", … - query
"select B, D, F where F > 2000" - headers
1
- data
In Excel
=CHOOSECOLS(FILTER(A2:F13,F2:F13>2000),2,4,6). Add the header row on top with VSTACK if you need it.Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =VSTACK(CHOOSECOLS(A1:F1,2,4,6),CHOOSECOLS(FILTER(A2:F13,F2:F13>2000),2,4,6))Excel only | spills 6 × 3 | The Excel equivalent, header row included. |
| =FILTER({B2:B13,D2:D13,F2:F13},F2:F13>2000) | spills 5 × 3Different result | FILTER on the three columns joined side by side, when you don't want the header. No header row. |
Common mistakes
- Text inside the query needs single quotes, because the whole query sits inside double quotes:
where C = 'East'. - Clauses must come in this order: select, where, group by, pivot, order by, limit, offset, label, format. Out of order, QUERY returns #VALUE!.
- Leave out the last argument and QUERY guesses how many header rows there are, and can swallow your first order as a header. Always give 1 or 0.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Use the QUERY function
H1, use QUERY to return the Rep, Product and Revenue columns of every order with revenue over 2000, with the header row on top.Questions
Can QUERY use column names instead of letters?
No. With a range, use the column letters. With an array such as {B2:B13,F2:F13}, use Col1, Col2 and so on.
Is QUERY case-sensitive?
Yes, for text: where C = 'east' finds nothing. Compare lower(C) = 'east' to ignore case.
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine.