aggregate
MIN
Returns the smallest non-NULL value in a group, using natural ordering for the column's data type. Works for numbers, dates, and strings (lexicographic).
MIN(expression) Parameters / Modifiers
| Parameter | Purpose |
|---|---|
| OVER (...) | Windowed minimum across a partition |
| FILTER (WHERE ...) | Postgres: conditional minimum |
| COLLATE | Force a specific collation for string comparisons |
Examples
SELECT MIN(price) FROM products; Cheapest product price in the table
SELECT MIN(created_at) FROM users WHERE country = 'IN'; Earliest signup date among Indian users
SELECT category, MIN(price) FROM products GROUP BY category; Cheapest item per category
SELECT MIN(name) FROM users; Alphabetically first name (locale/collation dependent)
Dialect notes / Gotcha
String comparisons obey the column's collation — MIN on a case-insensitive collation may differ from a binary one. NULLs are ignored, so MIN over all-NULL groups returns NULL.
Related functions
MAX
Returns the largest non-NULL value in a group by the column's natural ordering. Useful for latest timestamps, top prices, or alphabetically last strings.
GREATEST / LEAST
Return the largest (GREATEST) or smallest (LEAST) of the provided arguments row-by-row — not across rows, which is MIN/MAX. NULL handling differs by engine: Postgres ignores NULL args, MySQL returns NULL if any argument is NULL.
COUNT
Returns the number of rows matching a query, optionally counting non-NULL values of an expression or distinct values. COUNT(*) counts every row including NULLs, while COUNT(expr) skips NULLs.
SUM
Adds up all non-NULL numeric values in a column or expression. Returns NULL (not 0) if every input row is NULL or the result set is empty.
AVG
Computes the arithmetic mean of non-NULL numeric values. NULL rows are excluded from both the sum and the divisor, so AVG is not equivalent to SUM/COUNT(*) when NULLs are present.
← All SQL functions · SQL cheat sheet · Window functions · PostgreSQL cheat sheet