LAST_VALUE()

You are viewing an old version of this article. View the current version here.

Syntax:

LAST_VALUE(expr,[expr,...])

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.

Examples:

MariaDB [test]> create table t1 (a int, b int);
MariaDB [test]> insert into t1 values(1,10),(2,20);
MariaDB [test]> delete from t1 where a=1 and last_value(@a:=a,@b:=b);
MariaDB [test]> select @a,@b;
+------+------+
| @a   | @b   |
+------+------+
|    1 |   10 |
+------+------+

See also

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.