Google Sheets QUERY Function: The Complete Guide
QUERY Function Basics is a Google Sheets function that query uses a sql-like syntax to filter and sort data. Formula Genius generates and validates this formula automatically from a plain-English prompt.
QUERY brings SQL-like power to Google Sheets. Filter, sort, group, and aggregate data with a single formula.
The Formula
"Show all rows where Department is Sales, sorted by Revenue descending"
=QUERY(A1:D100,"SELECT * WHERE B='Sales' ORDER BY D DESC")
QUERY uses a SQL-like syntax to filter and sort data. SELECT * returns all columns, WHERE filters rows, and ORDER BY sorts results.
Step-by-Step Breakdown
- A1:D100 is the data range (including headers)
- SELECT * returns all columns (or specify: SELECT A, B, D)
- WHERE B='Sales' filters to rows where column B equals Sales
- ORDER BY D DESC sorts by column D in descending order
- String values in WHERE must be in single quotes
Edge Cases & Warnings
- Column references use letters (A, B, C), not column names
- Dates require special format: date '2026-01-01'
- Mixed data types in a column can cause unexpected results
- QUERY with headers: add third argument for header row count
Examples
"Department=Sales, sorted by Revenue"
All Sales rows, highest revenue first
"Department=Engineering, top 5 by Revenue"
Add LIMIT 5 to the query string
Frequently Asked Questions
Is QUERY available in Excel?
No. QUERY is exclusive to Google Sheets. The closest Excel equivalents are FILTER + SORT functions in Excel 365, or Power Query for complex transformations.
Can I reference cell values in QUERY?
Yes: =QUERY(A1:D100,"SELECT * WHERE B='"&E1&"'"). Concatenate the cell reference into the query string.
Can't find what you need?
Describe any formula in plain English and Formula Genius will generate, explain, and validate it — instantly.