PostgreSQL 18 reference · Aggregate Functions

PostgreSQL MIN() Function

Return the smallest value in a group. Works with numbers, text, dates and, since PostgreSQL 18, arrays.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

min(expression)

Parameters

ParameterDescription
expression A column or expression.

Return value

The smallest value, or NULL.

Examples

Dates and text
SELECT min(hire_date) AS first_hire, min(name) AS first_alphabetically
FROM employees;

Output

 first_hire | first_alphabetically
------------+----------------------
 2018-03-01 | Diego Silva
(1 row)

Run this on your computer — see “Get Started” for setup.

Per group
SELECT category_id, min(price) AS cheapest
FROM products
GROUP BY category_id
ORDER BY category_id;

Output

 category_id | cheapest
-------------+----------
           1 |    29.99
           2 |    24.99
           3 |    12.00
           4 |     5.50
        NULL |   120.00
(5 rows)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 18Accepts arrays and composite types.

In other languages

Was this page helpful?