๐ŸŸฉ Sheet Formulas

Google Sheets QUERY Formula Builder

Quick answer: To filter and sort data in Google Sheets with one formula, use =QUERY(range, "SELECT col WHERE condition ORDER BY col", headers) โ€” for example =QUERY(A1:D, "SELECT A, B WHERE C > 100 ORDER BY B DESC LIMIT 10", 1) returns columns A and B for every row where column C is over 100, sorted by B, top 10. Text values in WHERE use single quotes (WHERE B = 'Apple'); numbers are unquoted.

Pick your data range, the columns to show, any WHERE filters, sorting and a row limit โ€” this builder writes the exact =QUERY() formula for Google Sheets with the SQL-like query string quoted correctly. Add as many filter conditions as you need and copy the result.

=QUERY(A1:D, "SELECT A, B", 1)

WHERE conditions (filters)

How this QUERY builder works

The QUERY function runs a small SQL-like query over a range. The second argument is a text string with clauses in a fixed order: SELECT (which columns), WHERE (filter rows), ORDER BY (sort), LIMIT (cap rows). The third argument is how many header rows your range has (usually 1).

  • SELECT uses column letters as they sit in the range, not header names โ€” SELECT A, C, or SELECT * for every column.
  • WHERE compares a column to a value. Numbers are written plain (WHERE C > 100); text must be wrapped in single quotes (WHERE B = 'Apple'). Combine filters with AND / OR.
  • contains / starts with / ends with do partial text matching โ€” WHERE B contains 'red'.
  • ORDER BY sorts, add DESC for largest-first.
  • LIMIT returns only the first N rows.

The builder above quotes text values and assembles the clause order for you, so you only paste and go.

Common ready-to-paste examples

Show columns A and B for rows where column C is over 100:

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

Filter by a text value (remember single quotes):

=QUERY(A1:D, "SELECT A, B WHERE B = 'Apple'", 1)

Top 10 rows by column D, highest first:

=QUERY(A1:D, "SELECT A, D ORDER BY D DESC LIMIT 10", 1)

Partial text match with contains:

=QUERY(A1:D, "SELECT * WHERE C contains 'invoice'", 1)

Two conditions combined with AND:

=QUERY(A1:D, "SELECT A, B, C WHERE C > 100 AND B = 'Open'", 1)

FAQ

Why does my QUERY say 'unable to parse query string'?

Almost always a quoting problem: text values in WHERE must use single quotes, like WHERE B = 'Apple', and clause order must be SELECT, then WHERE, then ORDER BY, then LIMIT. The builder above fixes both automatically.

How do I reference columns in QUERY?

Inside the query string you use column letters as they appear in the range (A, B, C...), not the header text. Use SELECT * to return every column.

Can QUERY filter by text containing a word?

Yes โ€” use contains, starts with or ends with, e.g. WHERE B contains 'red'. These are case-insensitive partial matches.

What does the last number in QUERY mean?

It is the number of header rows in your range. Use 1 if your data has a single header row, or 0 if it has none.