Google Sheets: QUERY Function

The QUERY function executes a query on all the data in a range and returns a data array.

Queries are written in a language very similar to SQL.

Usage:

=QUERY(data, query)

or

=QUERY(data, query, headers)


About the QUERY function

QUERY is a very powerful function in Google Sheets that allows you to return data that meets one or more conditions, group, sort, filter, pivot, format data, process dates (or days, months, years of dates) and times, calculate sums, averages, maximums, etc.

This complete and free course on the QUERY function will allow you to learn to use this function step by step (with each new page, new elements are added to allow you to write increasingly precise queries).

Database

In the different examples in this section, the QUERY function will use the data from this (very small) database placed on a sheet named DB:

google sheets function query db

You can copy this small database to have it at hand and be able to do some tests yourself while following this course.

Start

If you are starting with this function, it is highly recommended to follow this course in order: