sqlite
  1. sqlite-min

SQLite MIN Function

In SQLite, the MIN() function is an aggregate function that returns the minimum value of a set of values. It can be used to find the smallest value in a column or a group of columns.

Syntax

The general syntax for using the MIN() function is as follows:

SELECT MIN(column_name) FROM table_name WHERE condition;

The function takes one argument, which is the name of the column to find the minimum value for. You can also use the function without a WHERE clause to find the minimum value for the entire column.

Example

Suppose we have a table called students with columns for student ID and their scores in a test. We can use the MIN() function to find the lowest score.

SELECT MIN(score) FROM students;

Output

The output of the example above will be a single value, which is the minimum score in the students table.

60

Explanation

In the example above, we select the minimum value of the score column from the students table using the MIN() function. Since we did not specify a WHERE clause, the function returns the minimum value for the entire column.

Use

The MIN() function is useful in scenarios where you want to find the minimum or smallest value in a column or a group of columns. It can be used to find the lowest score, age, or price in a table.

Important Points

  • The MIN() function returns NULL if the column contains NULL values.
  • You can use the function with multiple columns if you want to find the minimum value across several columns.
  • The function can be used in conjunction with other aggregate functions, such as COUNT(), AVG(), and SUM(), to perform more complex calculations.

Summary

In this tutorial, we learned about the SQLite MIN() function, which is an aggregate function that returns the minimum value of a set of values. We saw examples of using the function to find the lowest score in a table and how to use it with other aggregate functions to perform more complex calculations. It's important to be aware of the limitations of the function, such as its handling of NULL values and its ability to work with multiple columns.

Published on: