Google Sheets spreadsheet with a QUERY formula pulling filtered rows into a separate results table with arrows

How to Use the QUERY Function in Google Sheets (with Examples, 2026)

QUERY is the most powerful single function in Google Sheets — it filters, sorts, groups, and summarizes data using a SQL-like language, all in one cell. Here’s how to use it, clause by clause, with examples you can adapt.


QUERY Syntax

=QUERY(data, query, [headers])
  • data — the range to run against (e.g., A1:E100).
  • query — a quoted string of clauses (e.g., "SELECT A, C WHERE C > 100").
  • headers — how many header rows the data has (usually 1).

Inside the query string, reference columns by their spreadsheet letter (A, B, C…), not by header name.


1. SELECT — Choose Columns

Return only columns A and C:

=QUERY(A1:E100, "SELECT A, C", 1)

SELECT * returns every column.


2. WHERE — Filter Rows

=QUERY(A1:E100, "SELECT A, B, C WHERE C > 100", 1)

Combine conditions with AND / OR:

=QUERY(A1:E100, "SELECT * WHERE C > 100 AND B = 'Paid'", 1)
  • Wrap text values in single quotes: B = 'Paid'.
  • Wrap dates like this: WHERE D > date '2026-01-01'.

3. ORDER BY — Sort

=QUERY(A1:E100, "SELECT A, C ORDER BY C DESC", 1)

DESC for largest-first, ASC (default) for smallest-first.


4. GROUP BY — Summarize

Total column C for each value in column A:

=QUERY(A1:E100, "SELECT A, SUM(C) GROUP BY A", 1)

Aggregates available: SUM, COUNT, AVG, MAX, MIN. Any column in SELECT that isn’t aggregated must appear in GROUP BY.


5. LABEL and LIMIT

  • Rename headers in the output:
=QUERY(A1:E100, "SELECT A, SUM(C) GROUP BY A LABEL SUM(C) 'Total'", 1)
  • Cap the rows returned:
=QUERY(A1:E100, "SELECT A, C ORDER BY C DESC LIMIT 10", 1)

6. Query Another Sheet

Reference a range on a different tab:

=QUERY('Sales'!A1:E100, "SELECT A, C WHERE C > 100", 1)

To query a separate spreadsheet file, wrap IMPORTRANGE as the data argument and reference columns as Col1, Col2, etc.


7. Reference a Cell in the Query String

Build dynamic queries by concatenating a cell value into the string:

=QUERY(A1:E100, "SELECT A, C WHERE B = '" & G1 & "'", 1)

Now changing G1 changes the filter.


8. Troubleshooting

”Unable to parse query string”

A clause is out of order or quoting is wrong. The clause order is fixed: SELECT → WHERE → GROUP BY → ORDER BY → LIMIT → LABEL. Use single quotes for text inside the query, double quotes around the whole string.

#VALUE! — column mismatch

You referenced a column letter outside the data range, or mixed data types in a column. QUERY expects each column to be a single type; numbers stored as text cause this.

Results include the header row

Set the third argument to 1 so QUERY treats the first row as a header.

Dates won’t filter

Use the date keyword and ISO format: WHERE D >= date '2026-01-01'.


Related Google Sheets guides: How to use VLOOKUP · How to create a pivot table · How to use the IF function · How to remove duplicates · How to use conditional formatting

Ready to automate your busywork?

Carly schedules, researches, and briefs you—so you can focus on what matters.

Get Carly Today →

Or explore our free tools