QUERY Function in Google Sheets: A Beginner's Guide
Learn the Google Sheets QUERY function: select columns, filter with where, sort with order by, group and sum, and use cell values in conditions. With examples.
By Ayoub Farid · · 2 min read
QUERY is Google Sheets' most powerful function. It lets you ask questions of a table in a simple SQL-like language: pick columns, filter rows, sort, group and total, all in one formula. Excel has no direct equivalent.
Syntax
=QUERY(data, query, [headers])
- data: the table, e.g.
A1:E500 - query: the instructions, in double quotes
- headers: number of header rows (usually 1)
Columns are referred to by letter: A, B, C…
Select columns
=QUERY(A1:E500,"select A, C, E",1)
Filter rows
=QUERY(A1:E500,"select * where C = 'Coffee'",1)
=QUERY(A1:E500,"select * where E > 100",1)
=QUERY(A1:E500,"select * where C = 'Coffee' and E > 100",1)
Text in single quotes inside the double-quoted query.
Sort
=QUERY(A1:E500,"select * order by E desc",1)
Group and sum (a pivot table in one formula)
=QUERY(A1:E500,"select C, sum(E) group by C order by sum(E) desc",1)
Total sales per category, largest first.
Limit
=QUERY(A1:E500,"select A, E order by E desc limit 5",1)
Top 5.
Use a cell value in the condition
=QUERY(A1:E500,"select * where C = '"&H1&"'",1)
Join the cell into the query with &, keeping the single quotes for text.
Dates
=QUERY(A1:E500,"select * where B >= date '2026-03-01'",1)
Dates use the date 'yyyy-mm-dd' format.
Tips
- Each column should contain one data type. Mixed columns cause blanks in results.
- Start simple and add one clause at a time.
- Clause order matters: select, where, group by, order by, limit.
For Excel users, FILTER plus SUMIFS and SORT cover most of the same jobs.
Frequently asked questions
What does QUERY do in Google Sheets?
It filters, sorts, groups and summarises data using a SQL-like language.
Is there QUERY in Excel?
No direct equivalent. Use FILTER, SORT, SUMIFS, pivot tables or Power Query.
Why does my QUERY return blank values?
The column mixes numbers and text; QUERY uses the majority type and blanks the rest.
How do I use a cell reference in QUERY?
Join it into the query string: "where C = '"&H1&"'".