Skip to content

ANY_VALUE

Function Description

ANY_VALUE returns with any value in the range.

Function Syntax

> ANY_VALUE(arg)

Parameter definition

Parameters Description
arg can be of any type. When arg is NULL, the row does not participate in the calculation.

Return value

The return type and the input type are the same.

Note: The execution result of ʻANY_VALUE` is uncertain, and the same input may result in different execution results.

Example

> create table t1(
    -> a int,
    -> b int,
    -> c int
    -> );
> create table t2(
    -> a int,
    -> b int,
    -> c int
    -> );
> insert into t1 values(1,10,34),(2,20,14);
> insert into t2 values(1,-10,-45);
> select ANY_VALUE(t1.b) from t1 left join t2 on t1.c=t1.b and t1.a=t1.c group by t1.a;
+-----------------------+
| any_value(t1.b) |
+-----------------------+
| 10 |
| 20 |
+-----------------------+
2 rows in set (0.01 sec)
> select 3+(5*ANY_VALUE(t1.b)) from t1 left join t2 on t1.c=t1.b and t1.a=t1.c group by t1.a;
+--------------------------------+
| 3 + (5 * any_value(t1.b)) |
+--------------------------------+
| 53 |
| 103 |
+--------------------------------+
2 rows in set (0.00 sec)