FIRST
Description
Returns the first element of the specified source column for each element in a group.
FIRST can be applied to any data type. The data type of the result is the same as the input column data type.
Syntax
FIRST ( table.input_column [, ORDER BY table.column [ASC|DESC] ] )
table.input_column: The column which should be aggregated.
ORDER BY (optional): Elements of the specified column are used to determine the first element.
ASC
orDESC
can be specified to use ascending or descending ordering. If the order direction is not specified, the ascending (ASC
) order is used. UsingFIRST
with descending order is equivalent to using LAST with ascending order.
NULL handling
NULL values are ignored, so they do not influence the result. If all the values of a group are NULL, the result for this group is also NULL.
Examples
[1] This example computes the first element of a column. | ||||||||||
| ||||||||||
|
[2] This example computes the first value grouped by country. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
|
[3] This example demonstrates the use of the optional ORDER BY clause. | |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
|
[4] This example computes the first element in a group with null values. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
|