How to Use QUERY in Google Sheets

By Tomosuke Hasegawa · Updated Oct 29, 2026 · Intermediate · 9 min read · includes 2 free exercises

In short: QUERY runs a short, SQL-like command on a range. You can filter, sort and summarize in one formula: =QUERY(data, query, [headers]). The command goes in quotation marks, for example "select A, C where C > 100".

What QUERY does

QUERY lets you ask a table a question in a small command language, the Google Visualization API Query Language. One formula can pick columns, filter rows, group and total values, and sort the result. It replaces what would otherwise take FILTER, SORT, SUMIF and more.

QUERY syntax

=QUERY(data, query, [headers])

In the query you can refer to columns by letter (A, B) or as Col1, Col2. The examples below use letters, with data that starts in column A.

A step-by-step example

Here is a small sales table in cells A1:C7.

ABC
1RegionProductSales
2EastNotebook120
3WestPen45
4EastPen60
5NorthNotebook80
6WestNotebook150
7EastBackpack200

select and where

To show only the Region and Sales columns for sales above 100:

=QUERY(A1:C7, "select A, C where C > 100", 1)

This returns the header row plus three rows: East 120, West 150 and East 200.

When you compare text in a where clause, put the text in single quotes inside the query, as in "select A, C where B = 'Pen'".

group by

To total the sales for each region:

=QUERY(A1:C7, "select A, sum(C) group by A", 1)

This returns one row per region: East 380, North 80 and West 195. Every column in the select clause must either be in group by or be wrapped in an aggregate such as sum().

order by

To sort the result, add an order by clause at the end:

=QUERY(A1:C7, "select A, sum(C) group by A order by sum(C) desc", 1)

The biggest region comes first.

Common QUERY mistakes

Try it yourself

Use the sales table above (A1:C7). Type your formula into the box, starting with =, then press Check.

Exercise 1: Select and filter

Using the sales table above (A1:C7, one header row), write a QUERY that shows the Region and Sales columns for rows where Sales is greater than 100.

Hint: "select A, C where C > 100". Add 1 as the headers argument.

Exercise 2: Total by region

Write a QUERY that shows each Region with the total of Sales for that region.

Hint: use sum(C) in the select clause and group by A.

What to learn next

Syntax and rules in this guide were checked against Google's QUERY help page. See all guides.