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

> Selects the last encountered value of a column.

# anyLast

<h2 id="anyLast">
  anyLast
</h2>

Introduced in: v1.1.0

Selects the last encountered value of a column.

<Warning>
  As a query can be executed in arbitrary order, the result of this function is non-deterministic.
  If you need an arbitrary but deterministic result, use functions [min](/reference/functions/aggregate-functions/min) or [max](/reference/functions/aggregate-functions/max).
</Warning>

By default, the function never returns NULL, i.e. ignores NULL values in the input column.
However, if the function is used with the `RESPECT NULLS` modifier, it returns the last value reads no matter if NULL or not.

**Syntax**

```sql theme={null}
anyLast(column) [RESPECT NULLS]
```

**Aliases**: `last_value`

**Arguments**

* `column` — The column name. [`Any`](/reference/data-types/index)

**Returned value**

Returns the last value encountered. [`Any`](/reference/data-types/index)

**Examples**

**Usage example**

```sql title=Query theme={null}
CREATE TABLE tab(city Nullable(String)) ENGINE=Memory;
INSERT INTO tab (city) VALUES ('Amsterdam'), (NULL), ('New York'), ('Tokyo'), ('Valencia'), (NULL);
SELECT anyLast(city), anyLastRespectNulls(city) FROM tab;
```

```response title=Response theme={null}
┌─anyLast(city)─┬─anyLastRespectNulls(city)─┐
│ Valencia      │ ᴺᵁᴸᴸ                      │
└───────────────┴───────────────────────────┘
```
