Templates, guides & honest tool reviews for small business

Sunday, November 29, 2026

Google Sheets QUERY Function: Examples for Beginners

Google Sheets QUERY function examples for beginners
Illustration: Google Sheets QUERY function

The Google Sheets QUERY function lets you filter, sort and total a table with one formula that reads like a short sentence. If you know a little SQL, it will feel familiar, but you do not need SQL to use it. This guide covers the syntax, the most useful clauses with made-up data, and the errors beginners hit most often.

QUERY syntax

QUERY takes three arguments: the data range, the query text in quotes, and the number of header rows.

=QUERY(A1:D100, "select A, B", 1)

This returns columns A and B from the range and treats row 1 as a header. In a normal range, columns are written as letters (A, B, C).

Select all columns or only some

  • All columns: "select *"
  • Some columns: "select A, D"
Google Sheets QUERY with select and where to filter rows
Made-up orders table (illustration).

Filter rows with WHERE

Suppose A holds the customer, B the date, C the status and D the amount. To list only open orders:

=QUERY(A1:D100, "select * where C = 'Open'", 1)

Text goes in single quotes. Numbers do not need quotes:

=QUERY(A1:D100, "select * where D > 100", 1)

Combine rules with and and or:

=QUERY(A1:D100, "select A, D where C = 'Open' and D > 100", 1)

Sort with ORDER BY

=QUERY(A1:D100, "select A, D order by D desc", 1)

Use desc for largest first and asc for smallest first.

Google Sheets QUERY group by with sum and a label
Totals per customer (illustration).

Total by group with GROUP BY

To add up the amount for each customer:

=QUERY(A1:D100, "select A, sum(D) group by A", 1)

Other functions you can use are count, avg, min and max. Rename a result column with label:

=QUERY(A1:D100, "select A, sum(D) group by A label sum(D) 'Total'", 1)

Google Sheets QUERY order by desc with limit 5
Top five amounts (illustration).

Limit the number of rows

=QUERY(A1:D100, "select A, D order by D desc limit 5", 1)

This shows the five largest amounts.

Put a cell value inside the query

Join a cell into the query text with the ampersand. If F1 holds a number:

=QUERY(A1:D100, "select * where D > "&F1, 1)

For a text value in F1, add single quotes around it inside the text: "select * where C = '"&F1&"'".

Google Sheets QUERY errors: unable to parse query string and fixes
Common errors and fixes (illustration).

Common QUERY errors

  • Unable to parse query string. Check quotes, spelling and the order of clauses. The order is select, where, group by, order by, limit, label.
  • Text without single quotes. Write 'Open' with single quotes.
  • Wrong header count. The third argument must match the real number of header rows.
  • Dates in a condition. Dates need the word date and the format yyyy-mm-dd, for example where B >= date '2026-12-01'.

Google Sheets QUERY function: common questions

Is QUERY better than FILTER?

QUERY can sort, group and total in one formula. FILTER is simpler when you only need to keep some rows.

Can QUERY read data from another spreadsheet?

Yes. Put IMPORTRANGE inside it. See our guide to IMPORTRANGE with conditions, where imported columns are named Col1, Col2 and so on.

Does QUERY update by itself?

Yes. When the source data changes, the result changes too.

Related guides on Sheets AI Hub

Learn SUMIF with multiple criteria, build a dashboard, and see Google Sheets AI formulas.

العربية