MIN and MAX are standard SQL aggregate functions used to identify the minimum and maximum values within a result set or each GROUP BY partition. They accept any comparable data type (numeric, date, text, etc.) and ignore NULL values by default. When used without GROUP BY, they return a single row summarizing the entire dataset; with GROUP BY, they compute per-group extremes. Some dialects allow the DISTINCT keyword inside the function to consider only unique values, though this rarely changes the result unless duplicates are present. MIN and MAX can also operate on expressions, including CASE statements, arithmetic calculations, or concatenations, as long as the resulting values are comparable. Because they are deterministic, MIN and MAX always produce the same output for identical input and have no side effects. They are frequently paired with ORDER BY or subqueries to retrieve full rows containing the extreme values. Performance is generally efficient if the target column is indexed, but large GROUP BY operations can still be costly. Be mindful that MIN and MAX ignore NULLs; if you need to treat NULL as the lowest or highest value, use COALESCE or ORDER BY with NULLS FIRST/LAST.
expression
(Any comparable data type) - The value or expression to evaluate.DISTINCT
(keyword, optional) - Removes duplicate values before calculating the result (supported in most major databases).AVG, SUM, COUNT, GROUP BY, HAVING, ORDER BY, COALESCE, DISTINCT
SQL-86 (first ISO SQL standard)
Any comparable type works: numbers, dates, timestamps, strings, and even boolean values in some dialects.
You cannot directly include NULL. Wrap the column in COALESCE or a CASE expression to replace NULL with a sentinel value first.
Use a subquery: SELECT * FROM table t WHERE column = (SELECT MIN(column) FROM table); This returns every row equal to the global minimum.
DISTINCT only matters when duplicates exist in the input set. If duplicates are common, DISTINCT can change the result when using non-numeric collations or specialized data types.