Last Updated : 15 Jul, 2025
The MIN()
function in PostgreSQL is an essential aggregate function that returns the minimum value in a set of values. This function is highly useful in various data analysis and reporting tasks, allowing you to quickly identify the smallest values in your datasets.
Let us better understand the MIN() Function in PostgreSQL to better understand the concept.
SyntaxMIN(expression)
Where 'expression'
represents the column or expression from which you want to find the minimum value.
Let us take a look at some of the examples of the MIN() Function in PostgreSQL to better understand the concept. For example, we will be using the sample database (ie, dvdrental).
Example 1: Finding the Minimum Payment AmountThe following query retrieves the smallest payment amount recorded in the 'payment'
table.
Query:
SELECT MIN(amount)
FROM payment;
Output:
Explanation: This query scans the 'amount'
column in the 'payment'
table and returns the minimum value, which represents the lowest payment made by any customer.
The next example shows how to find the smallest payment made by each customer. This involves grouping the results by 'customer_id'
.
Query:
SELECT
customer_id,
MIN(amount)
FROM
payment
GROUP BY
customer_id;
Output:
Explanation: In this query, 'customer_id'
is used to group the payments. The MIN(amount)
function finds the smallest payment for each customer within these groups.
- The
MIN()
function computes the minimum value over a specified set of values, which can be an entire table or a subset defined by aWHERE
clause.MIN()
can be effectively combined withGROUP BY
to find minimum values within groups, and withHAVING
to filter groups based on aggregate conditions.- Although
MIN()
operates on a single column, you can include multipleMIN()
functions in a single query to find minimum values of different columns.MIN()
ignoresNULL
values in the computation.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4