# QUERY

web · from google sheets · no excel equivalent · sheets: not yet compared

runs SQL-like query on data range

## signature

```
QUERY(data, query, [headers])
```

returns: `array`

## arguments

- data: range: required
- query: text: required
- headers: number: optional

## examples

formula and result, asserted in the engine test suite.

| formula | result | with |
| --- | --- | --- |
| `=QUERY(R1:S4, "select A, B where B > 150")` | `south` | R1=region, R2=north, R3=south, R4=north, S1=amount, S2=100, S3=200, S4=300 |
| `=QUERY(R1:S4, "select A, B order by B desc limit 2")` | `region` | R1=region, R2=north, R3=south, R4=north, S1=amount, S2=100, S3=200, S4=300 |

## related

- [DECODEURL](https://deepcalc.com/docs/functions/decodeurl.md): decodes URL-encoded text
- [ENCODEURL](https://deepcalc.com/docs/functions/encodeurl.md): encodes text for use in URLs using percent encoding
- [FILTERXML](https://deepcalc.com/docs/functions/filterxml.md): selects values from an xml STRING with an xpath
- [IMPORTRANGE](https://deepcalc.com/docs/functions/importrange.md): imports a range from another deepcalc workbook, addressed as {namespace}/{name}: e.g. worldbank/gdp. Resolution is journaled, never live-silent: refreshing the workbook's Sources materializes the target values as ordinary ops, so every upstream change arrives as a reviewable diff. Each source can track the latest version or be pinned to a specific one (the Sources panel). Before the first refresh the cell shows #NAME?. The inline form ={ns}/{name}!worksheet!A1:B10 is equivalent.

## navigate

- [all web functions](https://deepcalc.com/docs/functions/web-functions.md)
- [function index](https://deepcalc.com/docs/functions.md): all 602 functions
- [error values](https://deepcalc.com/docs/errors.md) · [concepts](https://deepcalc.com/docs/concepts.md) · [limits](https://deepcalc.com/docs/limits.md)
- [everything in one file](https://deepcalc.com/llms-full.txt)

source: https://deepcalc.com/docs/functions/query