Link Search Menu Expand Document

MIN_BY

The MIN_BY function returns the value of arg column at the row in which the val column is minimal.

If there is more than one minimal values in val, then the first will be used.

Syntax

MIN_BY(arg, val)
Parameter Description
<arg> The column from which the value is returned.
<val> The column that is search for a minimum value.

Example

For this example, we will again use the prices table that was created above for the MIN function. The values for that table are below:

item price
apple 4
banana 25
orange 11
kiwi 20

In this example below, MIN_BY is used to find the item with the lowest price.

SELECT
	MIN_BY(item, price)
FROM
	prices

Returns: apple