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])
| Argument | What it is |
|---|---|
| data | The table, with headers. |
| query | The query, in double quotes: "select A, B where …". |
| headersoptional | How 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.
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.
In F1, show the order number and amount of the Monterrey orders, with their headers.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Order | City | Seller | Amount | ||||
| 2 | P-101 | Monterrey | Carmen | 1200 | ||||
| 3 | P-102 | Guadalajara | Jorge | 850 | ||||
| 4 | P-103 | CDMX | Carmen | 2300 | ||||
| 5 | P-104 | Monterrey | Lucía | 640 | ||||
| 6 | P-105 | CDMX | Jorge | 1750 | ||||
| 7 | P-106 | Guadalajara | Lucía | 980 | ||||
| 8 | P-107 | Monterrey | Jorge | 1500 | ||||
| 9 | P-108 | CDMX | Lucía | 410 | ||||
| 10 | P-109 | Guadalajara | Carmen | 1320 | ||||
| 11 | P-110 | Monterrey | Carmen | 760 | ||||
| 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.