first()

Aggregate. Returns the first value from the group of values.

Syntax

first ( expression, index )

Parameters

expression

The function returns the same datatype as the argument.

index

(Optional) The index accepts NULL values and integer datatypes. Returns the same datatype as the argument. Which row to use, as offset from the last row in the group based on the group order by sort order. If omitted or 0, uses the last row.

Usage

Returns the first value from a group of values. The function takes any datatype for the expression argument and an optional integer as the index argument, and returns the same datatype as the expression. The function performs a calculation on the specified expression and returns the first value, including NULL values.

If the argument is a pure column name, use as a scalar.

This function could be used in a first in first out (FIFO) fashion for accounts and stocks.