> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# FIRST_VALUE

> Returns the first group/frame value.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Aggregate · Window</span></div>

**Aliases:** [`first`](/query/sql/functions/aggregate/first)

RESPECT NULLS is default. IGNORE NULLS selects a non-NULL boundary value; all-NULL input yields NULL.

## Syntax

A window function keeps each input row and adds a result for that row. `PARTITION BY` groups rows with matching values; without it, all input rows form one group.

### Aggregate

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
first_value(value) [IGNORE NULLS | RESPECT NULLS]
```

### Window

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
first_value(value) [IGNORE NULLS | RESPECT NULLS] OVER ([PARTITION BY key] ORDER BY key [ROWS frame])
```

## Arguments

### Aggregate and window

| Name | Type | Required | Description |
| - | - | - | - |
| value | BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT | Yes | Value selected from the boundary row. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |

## Returns

* Type: same SQL type as value
* NULL behavior: RESPECT NULLS is default. IGNORE NULLS selects a non-NULL boundary value; all-NULL input yields NULL.
* Empty input: Returns NULL on empty input/frame.

## Properties

| Property | Value |
| - | - |
| Deterministic | Partial (Input order and tied ORDER BY values can change the selected row. Use a unique ordering key for windows.) |
| Supports DISTINCT | No |
| Supports window usage | Partial (Selects the first value in the frame; NULL-handling clauses are supported. RANGE offsets are not supported.) |
| Supports window frames | Partial (RANGE offsets are not supported; ROWS restrictions vary by form. See Usage notes.) |
| Exact result | Yes |

## Usage notes

* Grouped input order is unspecified; use a unique ordering key for stable window results.
* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* Query tools may report a DECIMAL result as DOUBLE or a TIME result as INTEGER. The returned value still keeps its decimal precision and scale, or its time type. A reported type does not convert the value.
* Supports DISTINCT: Adding DISTINCT does not remove duplicate input values.

## Examples

### Basic example

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH t(id,"value") AS (VALUES (1,10),(2,5),(3,20)) SELECT first_value("value") OVER (ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS result FROM t ORDER BY id LIMIT 1;
```

| result |
| - |
| 10 |

### All rows and running results, with NULL handling

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH sample(id, v) AS (VALUES (1, CAST(NULL AS INTEGER)), (2, 10), (3, 5))
SELECT id,
  first_value(v) RESPECT NULLS OVER (ORDER BY id ASC NULLS LAST
    ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS whole_partition,
  first_value(v) IGNORE NULLS OVER (ORDER BY id ASC NULLS LAST
    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_non_null
FROM sample ORDER BY id ASC NULLS LAST;
```

| id | whole\_partition | running\_non\_null |
| - | - | - |
| 1 | NULL | NULL |
| 2 | NULL | 10 |
| 3 | NULL | 10 |

## Limitations

* RANGE frames with a numeric or time offset are not supported.
* In grouped calls, DISTINCT does not remove duplicate input values. Selection can still vary when rows are tied or their order changes.
* The optional Boolean shorthand on FIRST is outside these calling forms; use the explicit one-argument function and NULL-treatment clause.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.