SQLite FIRST_VALUE() Function
Example
Show each product with the cheapest product in its category:
SELECT CategoryID, ProductName, Price,
FIRST_VALUE(ProductName) OVER (
PARTITION BY CategoryID
ORDER BY Price) AS Cheapest
FROM Products;
Try it Yourself »
Definition and Usage
The FIRST_VALUE() function returns the value from the first row in the window frame.
Note: Window functions need an OVER clause. Read more in the SQLite Window Functions chapter.
Tip: Also look at LAST_VALUE(), NTH_VALUE().
Syntax
FIRST_VALUE(expression) OVER (PARTITION BY column ORDER BY column)
Parameter Values
| Parameter | Description |
|---|---|
| expression | Required. The column or calculation to return |
Technical Details
| Return type: | Same as the input |
|---|---|
| Works in: | SQLite 3.25.0 and later |