How to Use the QUERY Function in Google Sheets
QUERY is the most powerful function in Google Sheets — a mini SQL language that selects, filters, groups, and sorts your data in a single formula. Here's how to read and write one without the learning curve.
The quick version: =QUERY(A1:C, "SELECT A, SUM(B) WHERE C = 'West' GROUP BY A", 1) reads your data, keeps only the West rows, and totals column B per value of column A — one formula instead of five. Here's how to build one.
The syntax
=QUERY(data, "query string", headers)
data is your range (include headers). query string is a SQL-like instruction in quotes. headers is how many header rows there are — usually 1.
The clauses you'll actually use
- SELECT — which columns:
SELECT A, B(orSELECT *for all). - WHERE — filter rows:
WHERE C > 1000, or text:WHERE B = 'West'. - GROUP BY — roll up with a total:
SELECT A, SUM(B) GROUP BY A. - ORDER BY — sort:
ORDER BY B DESC. - LIMIT — top N:
LIMIT 10.
Putting it together
Total sales by region, biggest first, over $1,000:
=QUERY(A1:C, "SELECT B, SUM(C) WHERE C > 1000 GROUP BY B ORDER BY SUM(C) DESC", 1)
Common gotchas
- Column references. Use letters (
A,B) when the first argument is a range; useCol1,Col2when it's an array (like IMPORTRANGE output). - Quotes. Text criteria go in single quotes inside the double-quoted string:
WHERE B = 'West'.
=IFERROR(QUERY(...), "").=QUIRIZ("total sales by region over $1,000, biggest first", "table") and it returns the same table.QUERY, but in plain English
Quiriz turns a plain-English question into the answer — no SELECT/WHERE/GROUP BY to write. Ask right in your sheet with =QUIRIZ(). Free to start.
Try Quiriz free →