---
title: "\u6700\u521D\u306E\u96C6\u8A08Function (*.fnc)"
description: "\u9806\u5E8F\u4ED8\u3051\u3055\u308C\u305F\u7D50\u679C\u30BB\u30C3\u30C8\u306B\u304A\u3044\u3066\u3001null \u3067\u306A\u3044\u6700\u521D\u306E\u5024\u3092\u6C42\u3081\u308B\u30B0\u30EB\u30FC\u30D7\u95A2\u6570\u3067\u3059\u3002"
language: ja
source_language: en
translation_state: complete
canonical: https://documentation.invantive.eu/ja/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-12-04T12:45:50Z
license: https://documentation.invantive.eu/ja/
---

## 構文

```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))
```

## 目的

順序付けされた結果セットにおいて、`null`でない最初の値を求めるグループ関数です。 行の順序はソースによって決まります。決定的な結果を得るには、入れ子のクエリ内で`order by`と組み合わせてください。

## 例
次の例では、連絡先が格納されている順序に従って、連絡先リストから最初の担当者を取得します。
```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
```
次の例では、顧客ごとにアルファベット順で最初の担当者を取得します。たとえば、督促状の既定の宛先として使用できます。
```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
```

