How to use the QUERY function in Google Sheets
In Google Sheets (verified 2026-10-24), type =QUERY(A1:D100, "select A, C where D > 100 order by C desc", 1) to filter and sort a table without helper columns.
The third argument is the header row count (often 1). QUERY is ideal for dashboards that should update when source data changes — pair it with FILTER or UNIQUE when you need simpler cases.
Works in Google Sheets in the browser and mobile app (formulas calculate in the cloud). Column letters inside the query string refer to columns in the range you pass, not the whole sheet.
Build a QUERY formula
Select and filter
- Click an empty cell with room for results.
- Enter
=QUERY(A1:D200,"select A, B, D where D >= 50",1). - Press Enter — matching rows spill below.
Aggregate
- Try
=QUERY(A1:D200,"select A, sum(D) group by A",1)for totals by category. - Add
order by sum(D) descinside the string to rank groups.
Keep it stable
- Use closed ranges or wider limits you expect to fill (
A1:D). - Wrap with
IFERROR(...,"No rows")for empty results. - Do not put user-edited cells inside the spill area.
Our take: QUERY for reports, FILTER for one-off views
Use QUERY when you need group by, averages or multi-column selects. Use FILTER/UNIQUE for quick “show rows where status = Open” without learning query syntax.
If it fails
- #VALUE!: often a bad clause, mixed data types in a column, or wrong header count.
- Column letters wrong: letters are relative to the range (first column of the range is A inside the query).
- Dates: use
date 'YYYY-MM-DD'inside the query string. - Need joins across sheets: QUERY one IMPORTRANGE, or combine with {} arrays carefully.
Frequently asked questions
What does QUERY do in Google Sheets?
It runs a SQL-like select/filter/aggregate on a range and spills the result.
QUERY vs FILTER?
FILTER is simpler for boolean conditions; QUERY adds group by, pivot-like selects and ordering in one string.
Why is my QUERY empty?
No rows matched, header count is wrong, or the where clause compared incompatible types.
Can QUERY pull from another sheet?
Yes — =QUERY(Sheet2!A1:D,"select * where C = 'Open'",1).
Is QUERY case-sensitive?
String compares are case-sensitive unless you normalize with lower()/upper() in the clause.