MySQL MIN() Function
MySQL MIN() Function: Finding the Lowest Value in a Column
The MIN() aggregate function returns the smallest non-NULL value across matching rows. Like MAX(), it supports numeric columns, dates, timestamps, and string types using the column's collation rules.
Teams use MIN() to find each customer's first purchase date, the lowest price offered by any vendor, or the earliest hire date in a department. Paired with an index on the target column, MySQL can resolve ungrouped MIN() queries almost instantaneously.
Syntax
MIN([DISTINCT] expr)
expr: Comparable column or expression across rows.DISTINCT: Valid syntax, though it produces the same minimum as omitting it.
Practical Example
Suppose demo_employees lists staff hire dates (hire_date) and annual salaries by department. You can find the earliest hire date and entry salary floor for each team.
SELECT
department,
MIN(hire_date) AS earliest_hire,
MIN(salary) AS lowest_salary,
MIN(commission_pct) AS lowest_commission
FROM demo_employees
GROUP BY department;
| department | earliest_hire | lowest_salary | lowest_commission |
|---|---|---|---|
| Engineering | 2019-06-15 | 78000.00 | NULL |
| Sales | 2020-02-01 | 52000.00 | 3.50 |
| Finance | 2018-11-10 | 64000.00 | NULL |
In Sales, some reps have NULL commission and others have 3.50 or 7.00; MIN(commission_pct) skips the NULL rows and returns 3.50. In Engineering, every row has NULL commission, so MIN(commission_pct) returns NULL.
Common Mistakes & NULL Behavior
- NULLs do not win MIN():
MIN()ignoresNULLvalues completely unless every single row in the group isNULL(or the filtered result set is empty), in which case it returnsNULL. - Selecting non-grouped columns alongside MIN(): Querying
SELECT employee_name, MIN(salary)without grouping does NOT return the lowest-paid employee's name in MySQL. UseORDER BY salary ASC LIMIT 1or a subquery filteringWHERE salary = (SELECT MIN(salary) ...). - Using MIN() in a WHERE clause: You cannot write
WHERE MIN(price) < 10. Filter groups after aggregation usingHAVING MIN(price) < 10.
Frequently Asked Questions
Does MIN() work on VARCHAR and DATE columns?
Yes. On DATE or DATETIME columns, MIN() returns the earliest date. On VARCHAR columns, it returns the first string according to the column's collation order.
Why is SELECT MIN(id) FROM big_table so fast in MySQL?
When id has a B-tree index, InnoDB reads only the leftmost non-NULL leaf entry instead of scanning the table.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.