ClickHouse Functions/Aggregate Functions

min

Return the smallest value in a group — earliest signup, cheapest order, fastest response.

Signature

min(column: T): T

Returns

Same type as the input column

What it does

Returns the minimum value across all rows in a group. Skips NULLs in Nullable columns and returns the same type as the input column.

min is one of the core aggregate functions in ClickHouse. Given a column, it scans every row in the group and returns the single smallest value — the earliest signup date, the cheapest order total, the fastest response time. It works on numbers, dates, and strings, and returns the same type as the column it reads. Paired with GROUP BY it produces one minimum per bucket, which is why it shows up in almost every analytics rollup. When you need the row at the minimum rather than just the value itself, reach for argMin instead.

Notes

  • Aggregate functions skip NULLs — min ignores NULL values in a Nullable(T) column and returns the smallest non-NULL value.
  • The return type matches the column: min over a DateTime gives a DateTime, min over a Decimal gives a Decimal.
  • When you need the row at the minimum rather than the value itself, use argMin(col, argCol) — hypequery exposes it natively as .argMin(col, argCol, alias).

Example SQL

min in ClickHouse SQL

min-example.sql

TypeScript with hypequery

Use min in a typed TypeScript query

hypequery gives you a type-safe query builder for ClickHouse. The generated schema maps your ClickHouse columns to TypeScript types, and raw SQL expressions let you incorporate functions like min when you need them inside a builder query.

min-per-tenant.ts

Common questions

What developers search for with min

GROUP BY min in ClickHouse

min is the standard aggregate for the smallest value per group. Combine it with GROUP BY tenant_id to get the earliest signup or lowest price for every tenant in one pass.

min value vs the row at the minimum

min(total) tells you the cheapest order amount, but not which order it was. Use argMin(order_id, total) — .argMin() in hypequery — to pull the row sitting at that minimum.

ClickHouse min in TypeScript

hypequery has a native .min('column', 'alias') on the query builder, so you get the aggregate and a fully typed result back without writing raw SQL.

FAQ

Frequently asked questions about min

Does ClickHouse min ignore NULL values?

Yes. Like other aggregate functions, min skips NULLs in a Nullable column and returns the smallest non-NULL value. If every value in the group is NULL, the result is NULL.

What type does min return?

min returns the same type as the column it reads — a DateTime column yields a DateTime, a Decimal yields a Decimal, a String yields the lexicographically smallest String.

How do I get the row at the minimum, not just the value?

Use argMin(returnColumn, minColumn), which returns the value of one column at the row where another is smallest. hypequery exposes it as .argMin('order_id', 'total', 'cheapest_order_id').

Next step

Use min in a type-safe TypeScript query

hypequery generates TypeScript types from your ClickHouse schema. Use min alongside the builder, and reach for raw SQL expressions when the function is not exposed as a dedicated helper.