LAST is a non-standard aggregate function that returns the final value from a set of rows after ordering. Although not part of core ANSI SQL, it exists in Access, Informix, Firebird, and other engines. In standard SQL the same effect is achieved with the window function LAST_VALUE. Both approaches require a deterministic ORDER BY clause; without it, the concept of "last" is undefined. LAST (or LAST_VALUE) can also operate inside a partition, giving the last value within each group. Be aware that NULL handling follows normal ordering rules unless you use NULLS FIRST | LAST.
column_name
(any) - Column to evaluatesort_column
(any) - Column or expression that defines row orderFIRST, FIRST_VALUE, LAST_VALUE, ORDER BY, Window Functions
SQL:2003 (LAST_VALUE window function)
It returns the value stored in the row that appears last after a specified ORDER BY. When used with PARTITION BY it gives the last value within each partition.
You can syntactically, but the result is nondeterministic. Always supply ORDER BY to define what "last" means.
Use LAST_VALUE(column) OVER (ORDER BY some_column ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING).
Add the window frame clause ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. Without it, LAST_VALUE defaults to the frame ending at the current row.