SQLite MIN() Function
The SQLite multi-argument MIN() function returns the argument with the minimum value, or return NULL if any argument is NULL. The multi-argument MIN() function searches its arguments from left to right for an argument that defines a collating function and uses that collating function for all string comparisons. If none of the arguments to MIN() define a collating function, then the BINARY collating function is used.
Note: When single argument is used, MIN() function operates as an aggregate function.
Syntax
MIN(expr1, expr2, ... expr_n)
Parameters
expr1, expr2, ... expr_n |
Required. Specify the list of expressions to be evaluated. |
Return Value
Returns the smallest value in a list of expressions.
Example 1:
The example below shows the usage of MIN() function.
SELECT MIN(20, 30, 60, 10); Result: 10 SELECT MIN('20', '30', '60', '10'); Result: '10' SELECT MIN('D', 'G', 'X', 'A'); Result: 'A' SELECT MIN('Alpha', 'Beta', 'Delta', 'Gamma'); Result: 'Alpha' SELECT MIN('Alpha1', 'Alpha2', 'Alpha3', 'Alpha4'); Result: 'Alpha1' SELECT MIN(20, 30, 60, 10, NULL); Result: NULL
Example 2:
Consider a database table called Sample with the following records:
Data | x | y | z |
---|---|---|---|
Data 1 | 10 | 0 | 41 |
Data 2 | 20 | 15 | 42 |
Data 3 | 30 | 30 | 43 |
Data 4 | 40 | 45 | 44 |
Data 5 | 50 | 60 | 45 |
To get the smallest value, when values of column x, column y and column z are compared, the following query can be used:
SELECT *, MIN(x, y, z) AS MIN_Value FROM Sample;
This will produce the result as shown below:
Data | x | y | z | MIN_Value |
---|---|---|---|---|
Data 1 | 10 | 0 | 41 | 0 |
Data 2 | 20 | 15 | 42 | 15 |
Data 3 | 30 | 30 | 43 | 30 |
Data 4 | 40 | 45 | 44 | 40 |
Data 5 | 50 | 60 | 45 | 45 |
❮ SQLite Functions