Skip to content
Dropfile

QUERY Function

The most powerful function in Google Sheets. Uses a SQL-like query language to filter, sort, group, pivot, and aggregate data — all within a formula.

Google Sheets

Syntax

QUERY(data, query, [headers])

Parameters

ParameterDescription
dataThe range of cells to query.
queryThe query string using Google Visualization API Query Language (similar to SQL).
headers(optional)Number of header rows in the data. -1 for auto-detect.

Examples

Select specific columns where region is East

=QUERY(A1:D100, "SELECT A, C WHERE B = 'East'", 1)

Result: Returns columns A and C for rows where column B is 'East'

Group by category and sum sales

=QUERY(A1:C100, "SELECT A, SUM(C) GROUP BY A ORDER BY SUM(C) DESC", 1)

Result: Sales totals grouped by category, sorted highest first

Top 10 records by value

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

Result: Returns the top 10 rows sorted by column D

Tips & Best Practices

Related Formulas

Need a different formula?

Describe what you need in plain English and our AI will generate the formula for you.

Try Formula Generator