ClickHouse/docs/en/sql-reference/aggregate-functions/reference/anylast.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.3 KiB
Markdown
Raw Normal View History

---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/anylast
sidebar_position: 105
---
2022-08-15 17:22:10 +00:00
# anyLast
Selects the last value encountered, ignoring any `NULL` values by default. The result is just as indeterminate as for the [any](../../../sql-reference/aggregate-functions/reference/any.md) function.
2024-05-04 14:20:58 +00:00
**Syntax**
```sql
anyLast(column) [RESPECT NULLS]
2024-05-04 14:20:58 +00:00
```
**Parameters**
- `column`: The column name.
:::note
2024-11-03 16:59:56 +00:00
By default, the `anyLast` function never returns `NULL`. However, it supports the `RESPECT NULLS `modifier after the function name, which will ensure the function selects the last value passed, regardless of whether it is `NULL` or not.
Alias: `anyLastRespectNulls`
:::
2024-05-04 14:20:58 +00:00
**Returned value**
- The last value encountered.
**Example**
Query:
```sql
CREATE TABLE any_last_nulls (city Nullable(String)) ENGINE=Log;
INSERT INTO any_last_nulls (city) VALUES ('Amsterdam'),(NULL),('New York'),('Tokyo'),('Valencia'),(NULL);
SELECT anyLast(city), anyLastRespectNulls(city) FROM any_last_nulls;
2024-05-04 14:20:58 +00:00
```
```response
┌─anyLast(city)─┬─anyLastRespectNulls(city)─┐
│ Valencia │ ᴺᵁᴸᴸ │
└───────────────┴───────────────────────────┘
2024-11-01 18:37:48 +00:00
```