# 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/functions/decodeurl.md) — decodes URL-encoded text
- [ENCODEURL](https://deepcalc.com/functions/encodeurl.md) — encodes text for use in URLs using percent encoding
- [FILTERXML](https://deepcalc.com/functions/filterxml.md) — selects values from an xml STRING with an xpath

## navigate

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

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