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

> Calcula o valor de `arg` para um valor mínimo de `val`. Se houver várias linhas com o mesmo `val` máximo, não é determinístico qual dos `arg` associados será retornado.

# argMin

<div id="argMin">
  ## argMin
</div>

Introduzido em: v1.1.0

Calcula o valor de `arg` para o menor valor de `val`. Se houver várias linhas com `val` igual sendo o máximo, não é determinístico qual dos `arg` associados será retornado.
Tanto `arg` quanto `min` se comportam como [funções de agregação](/pt-BR/reference/functions/aggregate-functions); ambas [ignoram `Null`](/pt-BR/reference/functions/aggregate-functions#null-processing) durante o processamento e retornam valores diferentes de `Null` se houver valores diferentes de `Null` disponíveis.

**Veja também**

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

**Sintaxe**

```sql theme={null}
argMin(arg, val)
```

**Argumentos**

* `arg` — Argumento para o qual será encontrado o valor máximo. [`const String`](/pt-BR/reference/data-types/string)
* `val` — O valor mínimo. [`(U)Int8/16/32/64`](/pt-BR/reference/data-types/int-uint) ou [`Float*`](/pt-BR/reference/data-types/float) ou [`Date`](/pt-BR/reference/data-types/date) ou [`DateTime`](/pt-BR/reference/data-types/datetime) ou [`Tuple`](/pt-BR/reference/data-types/tuple)

**Valor retornado**

Retorna o valor de `arg` correspondente ao valor mínimo de `val`. O tipo corresponde ao tipo de `arg`.

**Exemplos**

**Uso básico**

```sql title=Query theme={null}
SELECT argMin(user, salary) FROM salary;
```

```response title=Response theme={null}
┌─argMin(user, salary)─┐
│ worker               │
└──────────────────────┘
```

**Exemplo mais completo com tratamento de NULL**

```sql title=Query theme={null}
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;
```

```response title=Response theme={null}
┌─argMin(a, b)─┬─min(b)─┐
│ a            │      0 │
└──────────────┴────────┘
```

**Uso de Tuple em argumentos**

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

```response title=Response theme={null}
┌─argMin(a, tuple(b, a))─┬─min(tuple(b, a))─┐
│ d                      │ (NULL,NULL)      │
└────────────────────────┴──────────────────┘
```
