---
title: filter function
description: Learn the syntax of the filter function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/filter
---

# `filter` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Filters the array in `expr` using the function `func`.

## Syntax

```
filter(expr, func)
```

## Arguments

* `expr`: An ARRAY expression.
* `func`: A lambda function.

## Returns

The result is of the same type as `expr`.

The lambda function may use one or two parameters where the first parameter represents the element and the second the index into the array.

## Examples

```sql
> SELECT filter(array(1, 2, 3), x -> x % 2 == 1);
 [1,3]
> SELECT filter(array(0, 2, 3), (x, i) -> x > i);
 [2,3]
> SELECT filter(array(0, null, 2, 3, null), x -> x IS NOT NULL);
 [0,2,3]
```

## Related functions

* [`exists` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/exists.md)
* [`forall` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/forall.md)
* [`map_filter` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_filter.md)
