MIN Function in Snowflake: Syntax and Examples

Formulas & functions · Updated November 22, 2026

The MIN function in Snowflake returns the minimum value from a set of numeric, string, or date/timestamp values, ignoring NULLs by default. It is used both as an aggregate function (with GROUP BY) and as a window function (with OVER).

What MIN Does in Snowflake

Snowflake’s MIN is a standard SQL aggregate that scans a column or expression and returns the smallest value. It works with all comparable data types: numbers, strings (using lexicographic order), dates, timestamps, and variants (using the same ordering rules as comparisons). NULLs are ignored unless every value is NULL, in which case it returns NULL.

Unlike some databases, Snowflake does not have a separate MIN_BY function (that’s in some other SQL dialects); you would use MIN with a subquery or window function to get the row containing the minimum.

Basic Syntax and Examples

The basic syntax is:

SELECT MIN(column_name) FROM table_name;

For example, given a table orders with columns order_id and order_total:

SELECT MIN(order_total) AS min_total FROM orders;

This returns the smallest order total. You can also use expressions, like MIN(order_total * 1.1) to get the minimum of a calculated value.

Using MIN with GROUP BY

To get the minimum per group, use GROUP BY. For instance, to find the minimum order total per customer:

SELECT customer_id, MIN(order_total) AS min_order_total
FROM orders
GROUP BY customer_id;

This returns one row per customer with their smallest order value. You can group by multiple columns, and the MIN applies to each group independently.

Using MIN as a Window Function

To see the minimum value across a partition without collapsing rows, use the OVER clause. For example, to add a column showing the minimum order total per customer while keeping all rows:

SELECT order_id, customer_id, order_total,
       MIN(order_total) OVER (PARTITION BY customer_id) AS customer_min_total
FROM orders;

You can also use ORDER BY inside the window to create a running minimum, though that is less common. The window function form is powerful for comparisons and analytics.

Handling NULLs and Empty Sets

Snowflake’s MIN ignores NULL values. If the column contains NULLs, they are not considered. If all values in the group are NULL, the function returns NULL. This is standard behavior but can surprise users who expect a zero or empty string. To treat NULLs as a specific value, use COALESCE before applying MIN:

SELECT MIN(COALESCE(order_total, 0)) FROM orders;

That treats NULL as 0 for the purpose of finding the minimum. For strings, NULLs are similarly ignored; if you want to include an empty string, that is a non-NULL value and will be considered.

MIN with Strings and Dates

For strings, MIN returns the lexicographically smallest string (based on the collation of the column). For dates and timestamps, it returns the earliest date/time. Example:

SELECT MIN(order_date) AS earliest_order FROM orders;

This works with both DATE and TIMESTAMP types. For strings, be aware that lexicographic order is case-sensitive by default in Snowflake (unless the column has a case-insensitive collation). For example, ‘apple’ is less than ‘Banana’ because uppercase letters come before lowercase in ASCII ordering.

Performance and Best Practices

Using MIN on a large table can be slow if the column is not indexed or if you are scanning many rows. Snowflake’s columnar storage and micro-partitions help, but you can optimize by:

  • Filtering with WHERE to reduce the scan.
  • Using clustering keys on columns you frequently aggregate.
  • Using MIN on a column that is already sorted or clustered can be faster because Snowflake can prune partitions.

For window functions, partitioning by a key that aligns with clustering can improve performance. Also, avoid using MIN on large text columns if you only need a numeric or date minimum.

Common Errors and Misconceptions

One common mistake is expecting MIN to return the row containing the minimum, not just the value. To get the entire row, you need a subquery or a window function with QUALIFY. For example:

SELECT * FROM orders
QUALIFY ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_total ASC) = 1;

This returns the first row per customer when sorted by order_total ascending, effectively the row with the minimum. Another misconception is that MIN works on boolean values; it does not. Booleans are not comparable in this way, so you would need to cast to integer (0/1) first.

Also, note that MIN is case-sensitive for strings by default. If you need case-insensitive minimum, use LOWER() or set a collation on the column.

Frequently Asked Questions

Does MIN ignore NULLs in Snowflake?

Yes, by default MIN ignores NULLs. If you need to treat NULL as a value, use COALESCE inside the function, like MIN(COALESCE(col, 0)).

How do I get the row with the minimum value?

Use a window function with QUALIFY or a subquery. For example: SELECT * FROM orders QUALIFY ROW_NUMBER() OVER (ORDER BY order_total) = 1; returns the row with the smallest order_total.

Can I use MIN on a string column?

Yes, it returns the lexicographically smallest string. Be mindful of case sensitivity; use LOWER(col) if you want case-insensitive comparison.

What is the difference between MIN and MIN_BY?

Snowflake does not have a MIN_BY function. To get the row associated with the minimum, use a window function or a join with a subquery.

Does MIN work on dates and timestamps?

Yes, it returns the earliest date or timestamp. It works exactly like numeric comparisons.

How can I find the minimum across multiple columns?

Use the LEAST function, which returns the smallest of several expressions: SELECT LEAST(col1, col2, col3) FROM table;. Note that LEAST returns NULL if any argument is NULL, unlike MIN which ignores NULLs.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.