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
Syntax
min(expression)
Parameters
| Parameter | Description |
|---|---|
expression |
A column or expression. |
Return value
The smallest value, or NULL.
Examples
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.
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
| Version | Change |
|---|---|
| PostgreSQL 18 | Accepts arrays and composite types. |
In other languages
MIN()· SQLite
Related
MAX()· Return the largest value in a group. Works with numbers, text, dates and, since PostgreSQL 18, arrays.GREATEST()· Return the largest of a list of values, ignoring NULLs. least() returns the smallest.- SQL Aggregate Functions · tutorial
- SQL GROUP BY · tutorial