Skip to main content

FIRST_VALUE (SQL)

A window function that assigns the first value of the field column within the window frame to each of the other values in that column.

Synopsis

FIRST_VALUE(field)

Description

FIRST_VALUE uses the value of the field column from the first row to assign to all rows in the specific window frame. FIRST_VALUE supports the ROWS clause.

Note that the NULL collates before all values, so if the value of field in the first row is NULL, all of the rows in the window will be NULL.

Arguments

field

A column that specifies which value to assign to all rows in that window frame.

Examples

The following example returns the first value of the Country column within each city:

SELECT FIRST_VALUE(Country) OVER (PARTITION BY City)

See Also

FeedbackOpens in a new tab