> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> It is an alias for any but it was introduced for compatibility with Window Functions, where sometimes it is necessary to process `NULL` values (by default all ClickHouse aggregate functions ignore NULL values).

# first_value

It is an alias for [`any`](/reference/functions/aggregate-functions/any) but it was introduced for compatibility with [Window Functions](/reference/functions/window-functions/index), where sometimes it's necessary to process `NULL` values (by default all ClickHouse aggregate functions ignore NULL values).

It supports declaring a modifier to respect nulls (`RESPECT NULLS`), both under [Window Functions](/reference/functions/window-functions/index) and in normal aggregations.

As with `any`, without Window Functions the result will be random if the source stream is not ordered and the return type
matches the input type (Null is only returned if the input is Nullable or -OrNull combinator is added).

<h2 id="examples">
  examples
</h2>

```sql theme={null}
CREATE TABLE test_data
(
    a Int64,
    b Nullable(Int64)
)
ENGINE = Memory;

INSERT INTO test_data (a, b) VALUES (1,null), (2,3), (4, 5), (6,null);
```

<h3 id="example1">
  Example 1
</h3>

By default, the NULL value is ignored.

```sql theme={null}
SELECT first_value(b) FROM test_data;
```

```text theme={null}
┌─any(b)─┐
│      3 │
└────────┘
```

<h3 id="example2">
  Example 2
</h3>

The NULL value is ignored.

```sql theme={null}
SELECT first_value(b) ignore nulls FROM test_data
```

```text theme={null}
┌─any(b) IGNORE NULLS ─┐
│                    3 │
└──────────────────────┘
```

<h3 id="example3">
  Example 3
</h3>

The NULL value is accepted.

```sql theme={null}
SELECT first_value(b) respect nulls FROM test_data
```

```text theme={null}
┌─any(b) RESPECT NULLS ─┐
│                  ᴺᵁᴸᴸ │
└───────────────────────┘
```

<h3 id="example4">
  Example 4
</h3>

Stabilized result using the sub-query with `ORDER BY`.

```sql theme={null}
SELECT
    first_value_respect_nulls(b),
    first_value(b)
FROM
(
    SELECT *
    FROM test_data
    ORDER BY a ASC
)
```

```text theme={null}
┌─any_respect_nulls(b)─┬─any(b)─┐
│                 ᴺᵁᴸᴸ │      3 │
└──────────────────────┴────────┘
```
