---
title: "Fonction d\u0027agr\u00E9gation First"
description: "Fonction de groupe renvoyant la premi\u00E8re valeur non null dans un ensemble de r\u00E9sultats ordonn\u00E9."
language: fr
source_language: en
translation_state: complete
canonical: https://documentation.invantive.eu/fr/docs/invantive-universalsql/grammar/aggregate-functions/first-aggregate-function
original: https://documentation.invantive.eu/en/docs/invantive-universalsql/grammar/aggregate-functions/first-aggregate-function
updated: 2026-11-21T18:48:29Z
license: https://documentation.invantive.eu/fr/
---

## Syntaxe

```mermaid
%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart TD
    firstAggregateFunction_start((START))
    firstAggregateFunction_start --> firstAggregateFunction_0_0[FIRST]:::quoted
    firstAggregateFunction_0_0 --> firstAggregateFunction_0_1["("]:::quoted
    firstAggregateFunction_0_1 --> firstAggregateFunction_0_2[<a href="Invantive UniversalSQL/Grammar/Expression" class="internal-link">expression</a>]
    firstAggregateFunction_0_2 --> firstAggregateFunction_0_3[")"]:::quoted
    firstAggregateFunction_0_3 --> firstAggregateFunction_end((END))
```

## Objet

Fonction de groupe retournant la première valeur non-`null` d'un ensemble de résultats ordonné. L'ordre des lignes est déterminé par la source ; combinez-la avec un `order by` dans une requête imbriquée pour obtenir un résultat déterministe.

## Exemples
L'exemple suivant renvoie la première personne de contact d'une liste de contacts, dans l'ordre d'enregistrement des contacts :
```sql
select first(cnt.contact_name)
from   csvtable
       ( passing 'Acme Industries#Alice Johnson#CFO|Acme Industries#Tom Peters#Accounts Payable|Bergmann GmbH#Erika Weber#Controller|Carlson Ltd#James Smith#CFO|Dubois SA#Marie Dupont#Accounts Payable'
         row delimiter '|'
         column delimiter '#'
         columns customer_name varchar2 position next
         ,       contact_name  varchar2 position next
         ,       role          varchar2 position next
       ) cnt

-------------------
Alice Johnson
```
L'exemple suivant renvoie pour chaque client la personne de contact la première par ordre alphabétique, par exemple comme destinataire par défaut d'une lettre de relance :
```sql
select srt.customer_name
,      first(srt.contact_name)
from   ( select cnt.customer_name
         ,      cnt.contact_name
         from   csvtable
                ( passing 'Acme Industries#Alice Johnson#CFO|Acme Industries#Tom Peters#Accounts Payable|Bergmann GmbH#Erika Weber#Controller|Carlson Ltd#James Smith#CFO|Dubois SA#Marie Dupont#Accounts Payable'
                  row delimiter '|'
                  column delimiter '#'
                  columns customer_name varchar2 position next
                  ,       contact_name  varchar2 position next
                  ,       role          varchar2 position next
                ) cnt
         order
         by     cnt.customer_name
         ,      cnt.contact_name
       ) srt
group
by     srt.customer_name
order
by     srt.customer_name

-------------------
Acme Industries    Alice Johnson
Bergmann GmbH      Erika Weber
Carlson Ltd        James Smith
Dubois SA          Marie Dupont
```

