Google Sheets QUERY Function: Complete Guide
Learn how to use the QUERY function in Google Sheets to filter, sort, and summarize data. Step-by-step examples with SELECT, WHERE, and GROUP BY.
Sheets Bootcamp
February 18, 2026
The QUERY function in Google Sheets filters, sorts, and summarizes data using a text-based query language borrowed from SQL. You write conditions in a quoted string, and QUERY returns the matching rows. It’s one of the most flexible functions in Sheets — a single formula can do what normally takes FILTER, SORT, and a pivot table combined.
This guide covers the QUERY syntax, walks through real examples with sales data, and shows how to use SELECT, WHERE, GROUP BY, and other clauses.
In This Guide
- QUERY Function Syntax
- How to Use QUERY in Google Sheets: Step-by-Step
- QUERY Clause Reference
- QUERY Examples
- Common QUERY Errors
- Tips and Best Practices
- Related Google Sheets Tutorials
- FAQ
QUERY Function Syntax
The QUERY function takes three arguments:
=QUERY(data, query, [headers]) | Parameter | Description | Required |
|---|---|---|
| data | The range of cells to query (e.g., A1:G18) | Yes |
| query | A text string written in Google’s query language (e.g., "SELECT A, B WHERE C > 10") | Yes |
| headers | The number of header rows in your data. Defaults to a best guess. | No |
The query string uses the Google Visualization API Query Language. It borrows keywords from SQL — SELECT, WHERE, GROUP BY, ORDER BY — but it is not full SQL. The biggest difference: you reference columns by letter (A, B, C), not by header name.
Inside the query string, columns are referenced by their letter in the data range. If your data starts in column A, then column A in the query is the first column of your data. If your range starts at column D, then column D in the query maps to the first column. Always match column letters to where your data actually starts.
How to Use QUERY in Google Sheets: Step-by-Step
We’ll use a sales records table to pull specific columns and filter rows based on revenue.
Sample Data

Identify your data range
You need a range with a header row and consistent data below it. In this table, A1:G11 covers the headers plus 10 data rows. The columns are Date (A), Salesperson (B), Region (C), Product (D), Units (E), Revenue (F), and Commission (G).
Write a SELECT query
Select an empty cell and enter:
=QUERY(A1:G11, "SELECT B, C, F") This pulls three columns from the data: Salesperson (B), Region (C), and Revenue (F). QUERY returns a new table with just those columns, including the header row.

Add a WHERE filter
Modify the formula to include a condition:
=QUERY(A1:G11, "SELECT B, D, F WHERE F > 400") This returns only the rows where Revenue (column F) exceeds $400. The result shows the Salesperson, Product, and Revenue for each qualifying sale.

Review the result set
QUERY returns a complete table — headers and matching data rows. For this query, you get 3 rows: Lee Jordan’s Remembrall ($525.00), George Weasley’s Sneakoscope ($570.00), and Ginny Weasley’s Nimbus 2000 ($624.75).

QUERY results spill into adjacent cells automatically. Make sure the cells below and to the right of your formula are empty, or QUERY returns a #REF! error.
QUERY Clause Reference
The query string supports several clauses. You can combine them in a single formula, but they must appear in this order: SELECT, WHERE, GROUP BY, PIVOT, ORDER BY, LIMIT, OFFSET, LABEL, FORMAT.
SELECT
Chooses which columns to return. Use * for all columns, or list specific column letters separated by commas.
=QUERY(A1:G11, "SELECT B, D, F") Returns only Salesperson, Product, and Revenue. For more patterns, see the QUERY SELECT guide.
WHERE
Filters rows based on a condition. Works with comparison operators (=, !=, >, <, >=, <=), text matching (contains, starts with, ends with, matches), and IS NULL / IS NOT NULL.
=QUERY(A1:G11, "SELECT * WHERE C = 'Hogsmeade'") Returns all columns, but only rows where Region is “Hogsmeade”. Text values inside WHERE must be wrapped in single quotes. For a complete walkthrough, see the QUERY WHERE guide.
GROUP BY
Groups rows by a column and applies aggregate functions: SUM, COUNT, AVG, MIN, MAX.
=QUERY(A1:G11, "SELECT C, SUM(F) GROUP BY C") Returns one row per region with the total revenue for each. See the QUERY GROUP BY guide for more aggregation patterns.
ORDER BY
Sorts the result set by one or more columns. Add ASC (ascending, default) or DESC (descending).
=QUERY(A1:G11, "SELECT B, F ORDER BY F DESC") Returns all rows sorted by Revenue from highest to lowest.
LIMIT
Restricts the number of rows returned.
=QUERY(A1:G11, "SELECT B, F ORDER BY F DESC LIMIT 3") Returns only the top 3 rows by revenue.
LABEL
Renames column headers in the result.
=QUERY(A1:G11, "SELECT C, SUM(F) GROUP BY C LABEL SUM(F) 'Total Revenue'") The aggregated column header changes from “sum Revenue” to “Total Revenue”.
You can chain multiple clauses in a single query string. They must follow the order: SELECT, WHERE, GROUP BY, PIVOT, ORDER BY, LIMIT, OFFSET, LABEL, FORMAT. Putting them out of order causes a parsing error.
QUERY Examples
Example 1: Filter by Text Match
You want to see all sales made by Ginny Weasley.
=QUERY(A1:G11, "SELECT A, D, F WHERE B = 'Ginny Weasley'") This returns 3 rows from the first 10 data rows: Hogsmeade Self-Stirring Cauldron ($360.00), Hogwarts Nimbus 2000 ($624.75), and Hogsmeade Deluminator ($330.00). The query checks column B (Salesperson) for an exact text match.

Text values in WHERE clauses must be wrapped in single quotes: 'Ginny Weasley', not double quotes. The outer formula already uses double quotes, so single quotes avoid conflicts. Text matching is case-sensitive — 'ginny weasley' returns no results.
Example 2: Aggregate with GROUP BY
You want total revenue by region.
=QUERY(A1:G11, "SELECT C, SUM(F) GROUP BY C LABEL SUM(F) 'Total Revenue'") This returns 3 rows — one for each region — with the summed revenue:
| Region | Total Revenue |
|---|---|
| Diagon Alley | $1,359.85 |
| Hogsmeade | $1,459.90 |
| Hogwarts | $960.75 |
The LABEL clause renames the aggregated column from the default “sum Revenue” to “Total Revenue”.

Example 3: Combined Clauses
You want the top 3 salespeople by total revenue, but only for sales over $300.
=QUERY(A1:G11, "SELECT B, SUM(F) WHERE F > 300 GROUP BY B ORDER BY SUM(F) DESC LIMIT 3 LABEL SUM(F) 'Revenue'") This chains five clauses: SELECT picks the Salesperson and aggregated Revenue. WHERE filters out sales under $300. GROUP BY totals each person’s qualifying sales. ORDER BY sorts highest first. LIMIT keeps only the top 3.

Common QUERY Errors
Parsing Error
The most common QUERY error. You see a message like: Unable to parse query string for Function QUERY parameter 2.
This happens when:
- A clause is misspelled (
SLECTinstead ofSELECT) - Clauses are in the wrong order (
WHEREbeforeSELECTstill works, butORDER BYbeforeWHEREdoes not — actually,WHEREmust come beforeGROUP BY) - Text values are missing single quotes:
WHERE B = Ginnyinstead ofWHERE B = 'Ginny' - Column letters don’t exist in the data range
Fix it by checking the query string character by character. The error message sometimes includes the position where parsing stopped.
#VALUE! Error from Mixed Data Types
QUERY expects each column to contain one data type. If a column has a mix of numbers and text, QUERY uses the majority type and ignores the minority. Rows with the “wrong” type disappear from results without warning.
This commonly happens when a numeric column contains text entries like “N/A” or “Pending” mixed in with numbers. Clean the data first, or use a separate column with a formula to handle the conversion.
QUERY silently drops rows when a column has mixed data types. You won’t get an error — the rows just won’t appear in the results. If your QUERY returns fewer rows than expected, check the source column for mixed text and numbers.
Wrong Header Count
If the headers parameter (third argument) is wrong, QUERY might treat data rows as headers or vice versa.
=QUERY(A1:G11, "SELECT B, F", 1) Setting headers to 1 explicitly tells QUERY the first row is a header. If you omit this parameter, QUERY guesses — and it usually guesses correctly. But when your data starts below row 1 or has multiple header rows, set it explicitly.
Date Handling
Dates in QUERY WHERE clauses need a special format:
=QUERY(A1:G11, "SELECT * WHERE A > date '2026-01-15'") Use the date keyword followed by the date in 'YYYY-MM-DD' format inside single quotes. Without the date keyword, QUERY treats the value as text and the comparison breaks.
Tips and Best Practices
-
Use column letters, not header names. Inside the query string,
Frefers to the sixth column of your data range. Header names don’t work. If your range isC1:H10, thenCin the query refers to the first column of that range. -
Wrap text values in single quotes.
WHERE B = 'Hogsmeade'works.WHERE B = "Hogsmeade"breaks because the double quotes collide with the formula’s outer quotes. -
Set the headers parameter explicitly. Adding
1as the third argument (=QUERY(A1:G11, "SELECT *", 1)) removes ambiguity. QUERY’s auto-detection works most of the time, but explicit is safer. -
Use FILTER for simple row filtering. If you only need to return rows matching a condition without sorting, grouping, or reshaping, FILTER is faster to write and easier to read. Reserve QUERY for when you need multiple clauses.
-
Combine with IMPORTRANGE for cross-spreadsheet queries.
=QUERY(IMPORTRANGE("url", "Sheet1!A1:G"), "SELECT *")lets you query data from a different file. See the QUERY with IMPORTRANGE guide for setup details.
When debugging a QUERY formula, start with "SELECT *" to return everything, then add one clause at a time. This makes it easy to find which clause causes the error.
Related Google Sheets Tutorials
- QUERY WHERE Clause — Filter rows using conditions, comparisons, and text matching
- QUERY SELECT — Choose specific columns and reorder them in the output
- QUERY GROUP BY — Aggregate data with SUM, COUNT, AVG, and other functions
- IF Function Guide — Conditional logic for evaluating true/false conditions per row
- VLOOKUP Complete Guide — Look up values from a table, useful when you need a single value instead of a filtered dataset
Frequently Asked Questions
What does the QUERY function do in Google Sheets?
QUERY filters, sorts, and summarizes data using a text-based query language similar to SQL. You write conditions like SELECT, WHERE, and GROUP BY inside a quoted string, and QUERY returns the matching rows and columns.
What language does QUERY use in Google Sheets?
QUERY uses the Google Visualization API Query Language. It borrows concepts from SQL (SELECT, WHERE, GROUP BY, ORDER BY) but is not full SQL. Column references use letters (A, B, C) instead of column names.
How do you filter rows with QUERY in Google Sheets?
Add a WHERE clause to your query string. For example, =QUERY(A1:G18, "SELECT * WHERE F > 400") returns only rows where column F exceeds 400. Use single quotes for text values: WHERE B = 'Ginny Weasley'.
Can you use QUERY with data from another sheet?
Yes. Reference the other sheet in the data argument: =QUERY('Sheet2'!A1:G18, "SELECT B, F"). You can also combine QUERY with IMPORTRANGE to pull data from a different spreadsheet file entirely.
What is the difference between QUERY and FILTER in Google Sheets?
FILTER returns rows that match a condition and is faster for simple filtering. QUERY can also sort, group, aggregate, limit, and relabel results in a single formula. Use FILTER for quick row filtering and QUERY when you need to reshape or summarize the data.