Skip to content

ANY_VALUE

  • expr: This parameter is the column or expression over which the ANY_VALUE function is applied in the SQL statement. It essentially specifies the column from which ANY_VALUE should select a value.
SELECT ANY_VALUE(employee_name), department
FROM employees
GROUP BY department;
employee_name | department
--------------
John | HR
Doe | Accounting
Alex | Sales

The ANY_VALUE() function in MySQL is used to select a random value from a set when used along with GROUP BY. In the above example, we group all employees by department. For each department, it outputs the name of a single random employee from each group (for example, ‘John’ from ‘HR’).