Google Sheets QUERY function

Filters, sorts and summarizes a table with a SQL-like language. It is the most powerful Sheets function. It has the same name in Spanish Sheets.

Syntax

English Sheets

=QUERY(data, query, [headers])

Spanish Sheets (Mexico locale)

=QUERY(datos, consulta, [encabezados])

Spanish Sheets (Spain, Latin America)

=QUERY(datos; consulta; [encabezados])

ArgumentWhat it is
dataThe table, with headers.
queryThe query, in double quotes: "select A, B where …".
headersoptionalHow many header rows the table has.

Example

QUERY(data, query, headers) filters and summarizes a table with a SQL-like language. The query goes in double quotes and is always in English: "select A, D where B = 'CDMX'". Columns are named by their letter and text goes in single quotes. The final 1 says there is one header row.

=QUERY(A1:D11,"select A, D where B = 'Monterrey'",1)

Common mistake

Keywords stay in English in any language, text goes in single quotes and text comparisons are case-sensitive.

About Ads

This site uses Google AdSense to display ads. These ads help us keep WebHerramientas completely free. Ads are managed by Google and meet strict security and privacy standards.

Advertising
Loading ad...

Ads help us keep WebHerramientas free for everyone

Practice QUERY

Type the formula in the sheet and check it instantly. Spanish or English function names both work. See all lessons

QUERY: select and where

QUERY(data, query, headers) filters and summarizes a table with a SQL-like language. The query goes in double quotes and is always in English: "select A, D where B = 'CDMX'". Columns are named by their letter and text goes in single quotes. The final 1 says there is one header row.

Example=QUERY(A1:D11,"select A, D where B = 'CDMX'",1)QUERY: same name in Spanish

In F1, show the order number and amount of the Monterrey orders, with their headers.

F1
ABCDEFGH
1OrderCitySellerAmount
2P-101MonterreyCarmen1200
3P-102GuadalajaraJorge850
4P-103CDMXCarmen2300
5P-104MonterreyLucía640
6P-105CDMXJorge1750
7P-106GuadalajaraLucía980
8P-107MonterreyJorge1500
9P-108CDMXLucía410
10P-109GuadalajaraCarmen1320
11P-110MonterreyCarmen760
12

The dotted outline shows how far the result should spill.

Frequently asked questions

What is QUERY called in Spanish?
It has the same name: QUERY. Functions that started in Google Sheets keep their English name even in a Spanish spreadsheet. What changes is the separator: Spain and much of Latin America separate arguments with semicolons.
Why does QUERY use semicolons in some spreadsheets?
It depends on each spreadsheet's locale, under File > Settings. Where the comma is the decimal mark (Spain, much of South America), arguments are separated by semicolons. Mexico and United States locales use commas.
What is the most common QUERY mistake?
Keywords stay in English in any language, text goes in single quotes and text comparisons are case-sensitive.