FIRST
Returns the first value found within a field or group. Optionally, you can apply a filter to limit the rows read. You can nest only one other aggregate function within FIRST.
Use only in Mapping Configuration tasks.
Syntax
FIRST( value [, filter_condition ] )
Argument | Required/ Optional | Description |
---|
value | Required | Any datatype except Binary. Passes the values for which you want to return the first value. You can enter any valid transformation expression. |
filter_condition | Optional | Limits the rows in the search. The filter condition must be a numeric value or evaluate to TRUE, FALSE, or NULL. You can enter any valid transformation expression. |
Return Value
First value in a group.
NULL if all values passed to the function are NULL or if no rows are selected (for example, the filter condition evaluates to FALSE or NULL for all rows).
Nulls
If a value is NULL, FIRST ignores the row. However, if all values passed from the field are NULL, FIRST returns NULL.
Group By
FIRST groups values based on group by fields you define in the transformation, returning one result for each group.
If there is no group by field, FIRST treats all rows as one group, returning one value.
Examples
The following expression returns the first value in the ITEM_NAME field with a price greater than $10.00:
FIRST( ITEM_NAME, ITEM_PRICE > 10 )
ITEM_NAME | ITEM_PRICE |
---|
Flashlight | 35.00 |
Navigation Compass | 8.05 |
Regulator System | 150.00 |
Flashlight | 29.00 |
Depth/Pressure Gauge | 88.00 |
Flashlight | 31.00 |
RETURN VALUE: Flashlight | |
The following expression returns the first value in the ITEM_NAME field with a price greater than $40.00:
FIRST( ITEM_NAME, ITEM_PRICE > 40 )
ITEM_NAME | ITEM_PRICE |
---|
Flashlight | 35.00 |
Navigation Compass | 8.05 |
Regulator System | 150.00 |
Flashlight | 29.00 |
Depth/Pressure Gauge | 88.00 |
Flashlight | 31.00 |
RETURN VALUE: Regulator System | |