Return the last value from a sequence. This function retrieves the most recently generated value from a sequence object.
Syntax
LAST_VALUE(expr,[expr,...])
LAST_VALUE(expr) OVER ( [ PARTITION BY partition_expression ] [ ORDER BY order_list ])
Description
LAST_VALUE() evaluates all expressions and returns the last. This is useful together with setting user variables to a value with @var:=expr, for example when you want to get data of rows updated/deleted without having to do two queries against the table.
CREATETABLEt1 (a int, b int);INSERT INTO t1 VALUES(1,10),(2,20);DELETEFROM t1 WHERE a=1ANDlast_value(@a:=a,@b:=b,1);SELECT @a,@b;+------+------+| @a | @b |+------+------+| 1 | 10 |+------+------+