# argMin (/docs/reference/sql/aggregate-functions/argmin)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Calculates the `arg` value for a minimum `val` value. If there are multiple rows with equal `val` being the maximum, which of the associated `arg` is returned is not deterministic.
Both parts the `arg` and the `min` behave as [aggregate functions](/reference/functions/aggregate-functions), they both [skip `Null`](/reference/functions/aggregate-functions#null-processing) during processing and return not `Null` values if not `Null` values are available.

**See also**

* [Tuple](/reference/data-types/tuple)

**Syntax**

```sql
argMin(arg, val)
```

**Arguments**

* `arg` — Argument for which to find the maximum value. [`const String`](/reference/data-types/string)
* `val` — The minimum value. [`(U)Int8/16/32/64`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Date`](/reference/data-types/date) or [`DateTime`](/reference/data-types/datetime) or [`Tuple`](/reference/data-types/tuple)

**Returned value**

Returns the `arg` value that corresponds to minimum `val` value. Type matches `arg` type.

**Examples**

**Basic usage**

```sql title=Query
SELECT argMin(user, salary) FROM salary;
```

```text title=Response
┌─argMin(user, salary)─┐
│ worker               │
└──────────────────────┘
```

**Extended example with NULL handling**

```sql title=Query
CREATE TABLE test
(
    a Nullable(String),
    b Nullable(Int64)
)
ENGINE = Memory AS
SELECT *
FROM VALUES((NULL, 0), ('a', 1), ('b', 2), ('c', 2), (NULL, NULL), ('d', NULL));

SELECT argMin(a, b), min(b) FROM test;
```

```text title=Response
┌─argMin(a, b)─┬─min(b)─┐
│ a            │      0 │
└──────────────┴────────┘
```

**Using Tuple in arguments**

```sql title=Query
SELECT argMin(a, (b, a)), min(tuple(b, a)) FROM test;
```

```text title=Response
┌─argMin(a, tuple(b, a))─┬─min(tuple(b, a))─┐
│ d                      │ (NULL,NULL)      │
└────────────────────────┴──────────────────┘
```

*Introduced in version 1.1.0.*
