How to Use the QUERY Function in Google Sheets
QUERY runs SQL-style statements against your sheet data. The syntax is =QUERY(data, query, [headers]) — so =QUERY(A1:C100, "select A, C where B > 10") returns columns A and C, only for rows where B is above 10. It replaces a stack of filters and helper columns with one formula.
The three arguments
| Argument | What it is | Example |
|---|---|---|
data | The range to query | A1:C100 |
query | The statement, in quotes | "select A, C where B > 10" |
headers | How many header rows the data has | 1 |
The headers argument is optional but worth setting — 1 tells Sheets your first row holds column names.
Columns are letters, not Col numbers
This is the key difference from QUERY-inside-IMPORTRANGE:
| Data source | Refer to columns as |
|---|---|
A range in the same sheet (A1:C100) | A, B, C |
Imported data (IMPORTRANGE(...)) | Col1, Col2, Col3 |
Get this wrong and you’ll see #VALUE!. If your QUERY wraps an IMPORTRANGE, you must use Col1 style. See how to use IMPORTRANGE in Google Sheets for that combination.
Worked examples
Select specific columns:
=QUERY(A1:D100, "select A, C", 1)
Filter rows by a condition:
=QUERY(A1:D100, "select * where B > 500", 1)
select * returns every column.
Sort the results:
=QUERY(A1:D100, "select A, B order by B desc", 1)
Group and total:
=QUERY(A1:D100, "select A, sum(D) group by A", 1)
That’s a pivot table in one formula — one row per category, with a total.
Filter and sort together:
=QUERY(A1:D100, "select A, B where B > 100 order by B desc limit 10", 1)
The ten highest rows above 100.
The clauses you can use
QUERY supports a readable subset of SQL:
| Clause | Does |
|---|---|
select | Which columns to return |
where | Filter rows |
group by | Combine rows by a column |
order by | Sort (asc or desc) |
limit | Return only the first N rows |
offset | Skip the first N rows |
label | Rename an output column header |
A full statement reads in that order: select ... where ... group by ... order by ... limit ....
Filtering with conditions
The where clause takes the usual operators, plus a few extras:
| To filter | Write |
|---|---|
| Equals text | where A = 'North' |
| Not equal | where A <> 'North' |
| Greater than | where B > 500 |
| Contains | where A contains 'north' |
| Starts with | where A starts with 'Nor' |
| Either/or | where A = 'North' or A = 'South' |
| Both | where A = 'North' and B > 500 |
Text needs single quotes inside the double quotes. The whole statement is wrapped in
", so strings within it use'.=QUERY(A1:C100, "select A where B = 'North'", 1).
Dates need a different approach — use date literals:
=QUERY(A1:C100, "select A where B > date '2026-01-01'", 1)
Renaming output columns
The label clause tidies up the output:
=QUERY(A1:C100, "select A, sum(C) group by A label sum(C) 'Total'", 1)
Without it, aggregated columns are headed “sum Sales” or similar. With it, you control the wording.
Where QUERY beats a filter
| Task | Filter view | QUERY |
|---|---|---|
| Hides rows in place | ✅ | ❌ (outputs elsewhere) |
| Result you can reference | ❌ | ✅ |
| Group and total | ❌ | ✅ |
| Updates automatically | ✅ | ✅ |
| Works inside other formulas | ❌ | ✅ |
Use a filter when you just want to look at a subset. Use QUERY when you need a result — something another formula or chart can read.
Common problems
| Problem | Cause |
|---|---|
#VALUE! | Usually column names — use Col1 not A when the data came from IMPORTRANGE |
#ERROR! with “Unable to parse query string” | A syntax slip: missing quotes, or a clause out of order |
| Only the first row appears | The headers argument is missing — add , 1 |
| Text conditions return nothing | They need single quotes: 'North', not "North" |
| Numbers treated as text | The source cells are text. Use VALUE() or fix the column format |
| Dates don’t filter | Use date 'YYYY-MM-DD' syntax, not a plain string |
QUERY pairs naturally with the rest of the lookup family — how to use VLOOKUP in Google Sheets for finding single values, and how to remove duplicates in Google Sheets when you need a clean list before querying it.
FAQ
What does QUERY do in Google Sheets?
It runs SQL-like statements against a range — selecting columns, filtering rows, grouping, sorting, and limiting results, all in one formula.
What’s the QUERY syntax in Google Sheets?
=QUERY(data, "select ... where ... group by ... order by ...", headers). The statement goes in double quotes, with text conditions in single quotes inside it.
Why does QUERY return #VALUE!?
Most often because the column references are wrong. Ranges in the same sheet use letters (A, B); data from IMPORTRANGE must use Col1, Col2.
Can QUERY replace a pivot table?
For many summaries, yes — =QUERY(data, "select A, sum(B) group by A", 1) produces a grouped total without building a pivot table. A pivot table is still better when you want to click and drag the layout.
How do I filter by date in QUERY?
Use a date literal: where B > date '2026-01-01'. A plain string like '2026-01-01' often won’t compare correctly.
Related guides
Google Sheets Formulas for Beginners (10 You Need to Know)
The 10 essential Google Sheets formulas every beginner needs — SUM, AVERAGE, COUNT, IF, and more, with working examples.
How to Add Checkboxes in Google Sheets (Tick Boxes)
Add checkboxes in Google Sheets with Insert → Checkbox, set custom checked/unchecked values, and count ticks with COUNTIF or a progress bar.
How to Create a Drop-Down List in Excel (Data Validation)
Add a drop-down list in Excel with Data Validation — pick from a typed list or a range on another sheet, and fix the errors that stop it working.