How to Use the QUERY Function in Google Sheets (Beginner Guide)

QUERY lets you filter, sort, summarise and reshape data in Google Sheets with one formula. If you’ve ever wished you could “ask” your spreadsheet a question, this is the function for it.

The syntax

=QUERY(data, "query", headers)
  • data: the range to search, for example A1:E500.
  • query: instructions written in a simple query language, inside quotation marks.
  • headers: the number of header rows (usually 1). Optional, but it’s safer to include it.

Example data

We’ll use a sales sheet with these columns in A1:E:

A: DateB: RegionC: RepD: ProductE: Amount
2026-09-01NorthSaraLaptop1200
2026-09-02SouthOmarMonitor300
2026-09-02NorthAliLaptop1150
2026-09-03EastMonaKeyboard45

In QUERY, you refer to columns by their letters: A, B, C and so on.

SELECT: choose columns

=QUERY(A1:E, "SELECT C, E", 1)

Returns only the Rep and Amount columns. SELECT * returns all columns.

WHERE: filter rows

=QUERY(A1:E, "SELECT * WHERE B = 'North'", 1)

Text values go in single quotes inside the double-quoted query. Numbers don’t need quotes:

=QUERY(A1:E, "SELECT * WHERE E > 1000", 1)

Combine conditions with AND and OR:

=QUERY(A1:E, "SELECT * WHERE B = 'North' AND E > 1000", 1)

Partial text matches use contains or starts with:

=QUERY(A1:E, "SELECT * WHERE D contains 'Lap'", 1)

Skip empty rows when using open ranges like A1:E:

=QUERY(A1:E, "SELECT * WHERE A IS NOT NULL", 1)

ORDER BY: sort results

=QUERY(A1:E, "SELECT * WHERE A IS NOT NULL ORDER BY E DESC", 1)

DESC sorts largest first; ASC (the default) sorts smallest first.

LIMIT: top results

=QUERY(A1:E, "SELECT C, E WHERE A IS NOT NULL ORDER BY E DESC LIMIT 5", 1)

Returns the top 5 sales.

GROUP BY: summarise like a pivot table

=QUERY(A1:E, "SELECT B, SUM(E) WHERE A IS NOT NULL GROUP BY B", 1)

Returns total sales per region. Other aggregates: COUNT, AVG, MIN, MAX.

LABEL: rename result headers

The previous query produces a header like “sum Amount”. Rename it with LABEL:

=QUERY(A1:E, "SELECT B, SUM(E) WHERE A IS NOT NULL GROUP BY B ORDER BY SUM(E) DESC LABEL SUM(E) 'Total Sales'", 1)

Clause order matters

Clauses must appear in this order, or you’ll get an error:

SELECT → WHERE → GROUP BY → PIVOT → ORDER BY → LIMIT → LABEL

Use a cell value in the query

To make the region selectable (for example, from a dropdown in H1), join the cell into the text:

=QUERY(A1:E, "SELECT * WHERE B = '" & H1 & "'", 1)

Combine this with a drop-down list to build a simple interactive report.

Filtering dates

Dates need the date keyword and the format yyyy-mm-dd:

=QUERY(A1:E, "SELECT * WHERE A >= date '2026-09-01'", 1)

Common errors

  • “Unable to parse query string”: check quotes, spelling and clause order.
  • “No column: Amount”: use column letters (E), not header names.
  • Missing or blank values: QUERY expects one data type per column. A column mixing numbers and text may return blanks for the minority type, so keep columns consistent.

Does Excel have QUERY?

No. In Excel 365 you can get similar results with FILTER, SORT and UNIQUE, or with Power Query for larger data cleaning jobs; see Power Query for Beginners. Not sure which tool fits you? Read Google Sheets vs Excel.

Related guides

1 thought on “How to Use the QUERY Function in Google Sheets (Beginner Guide)”

Leave a Comment