> ## 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.

> Selects the first encountered value of a column.

# any

<h2 id="any">
  any
</h2>

Introduced in: v1.1.0

Selects the first 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 or 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 first value reads no matter if NULL or not.

**Implementation details**

In some cases, you can rely on the order of execution.
This applies to cases when `SELECT` comes from a subquery that uses `ORDER BY`.

When a `SELECT` query has the `GROUP BY` clause or at least one aggregate function, ClickHouse (in contrast to MySQL) requires that all expressions in the `SELECT`, `HAVING`, and `ORDER BY` clauses be calculated from keys or from aggregate functions.
In other words, each column selected from the table must be used either in keys or inside aggregate functions.
To get behavior like in MySQL, you can put the other columns in the `any` aggregate function.

<Note>
  The return type of the function is the same as the input, except for LowCardinality which is discarded.
  This means that given no rows as input it will return the default value of that type (0 for integers, or Null for a Nullable() column).
  You might use the -OrNull combinator to modify this behaviour.
</Note>

**Syntax**

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

**Aliases**: `any_value`, `first_value`

**Arguments**

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

**Returned value**

Returns the first 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 (NULL), ('Amsterdam'), ('New York'), ('Tokyo'), ('Valencia'), (NULL);
SELECT any(city), anyRespectNulls(city) FROM tab;
```

```response title=Response theme={null}
┌─any(city)─┬─anyRespectNulls(city)─┐
│ Amsterdam │ ᴺᵁᴸᴸ                  │
└───────────┴───────────────────────┘
```
