LEAST()
Returns the smallest value from a list of expressions.
Description
LEAST returns the lowest value among its arguments — a row-level "min across
columns" (unlike the MIN aggregate, which is across rows). LEAST(3, 7, 5) is
3. Use it to cap a value or pick the earlier of two dates.
Syntax
LEAST(expr1, expr2, ...)Parameters
| Name | Description | Optional |
|---|---|---|
| expr1, expr2, ... | Two or more expressions of compatible types. | No |
Return Type
Returns the same type as the inputs.
Examples
Employees & Departments
Loading database engine...
Employees & Departments
Loading database engine...
LEAST vs MIN
LEAST compares values within a single row (across columns); MIN is an
aggregate that compares rows within a group.
Common Mistakes
- NULL handling. A single NULL argument can make the result NULL; wrap
inputs in
COALESCEif you want to ignore NULLs. - Mixing types. Arguments should be compatible types.
- Confusing with MIN.
LEASTis per-row, not per-group.
Related Functions
See also: GREATEST, MIN.