DevLearningTools

LEARN · SQL

SQL MIN()

MIN() returns the smallest value in a column, and it isn't limited to numbers, it works on text and dates too. Learn its syntax, how to scope it with WHERE, and how it differs from finding the whole row that holds that value.

Beacon Robotics' finance team has their total payroll from the last lesson. Their next question is sharper: "what's the lowest salary we're currently paying anyone?" That's exactly what MIN() answers, the smallest value in a column, collapsed to a single number.

Learning Objectives

  • Use MIN() to find the smallest value in a numeric column.
  • Recognize that MIN() also works on text and date columns, not just numbers.
  • Scope MIN() to a subset of rows using WHERE.
  • Understand why MIN() alone doesn't tell you which row that value belongs to.

A Column

Every salary value

MIN()

Compares every value

Smallest Value

One number back

MIN() on Numbers

MIN() scans every non-NULL value in the column and returns the smallest one. Like every aggregate function, the result is a single row with a single value, not one row per employee.

MySQL / MariaDB / PostgreSQL / SQLite / SQL Server / Oracle
SELECT MIN(salary) AS lowest_salary
FROM employees;

MIN() Isn't Just for Numbers

MIN() works on any data type that can be compared and ordered, dates compare chronologically (earliest wins), and text compares alphabetically (first in dictionary order wins). This surprises a lot of beginners who assume aggregate functions are a numbers-only tool, SUM() and AVG() are, but MIN() and MAX() aren't.

MySQL / MariaDB / PostgreSQL / SQLite / SQL Server / Oracle
SELECT MIN(hire_date) AS earliest_hire
FROM employees;

SELECT MIN(department) AS first_alphabetically
FROM employees;

Scoping MIN() with WHERE

WHERE still runs first, narrowing the rows down to Engineering only, then MIN() finds the smallest salary among just those rows. This is the same order of operations covered in the aggregate functions overview: filter first, summarize what's left.

MySQL / MariaDB / PostgreSQL / SQLite / SQL Server / Oracle
SELECT MIN(salary) AS lowest_engineering_salary
FROM employees
WHERE department = 'Engineering';

Try It Yourself

Write a query that finds the earliest hire_date among active employees (status = 'active').

Answer
SELECT MIN(hire_date) AS earliest_active_hire
FROM employees
WHERE status = 'active';

Frequently Asked Questions

Does MIN() ignore NULL values, like the other aggregate functions?

Yes. A NULL in the column is simply skipped when MIN() compares values, exactly like SUM(), AVG(), and MAX(). If every value in the column is NULL, MIN() returns NULL.

Can MIN() find the smaller of two columns in the same row, like salary vs. bonus?

No, that's a different problem entirely, a row-by-row comparison rather than a summary across many rows. MIN() is an aggregate function: it looks down a column across many rows. Comparing two columns within the same row needs a different tool (MySQL and PostgreSQL have LEAST(), SQL Server and Oracle typically use a CASE expression), not covered in this course yet.

Common Beginner Mistakes

Expecting MIN(salary) to also return the employee's name

MIN() returns one value, the smallest salary itself, not the row it came from. SELECT first_name, MIN(salary) FROM employees doesn't work for the same reason covered in the aggregate functions overview, a per-row column can't sit next to a single summarized value without GROUP BY. To find who has the lowest salary, the right tool is ORDER BY salary ASC combined with LIMIT (or TOP, or FETCH FIRST), both already covered in Module 1.

Assuming MIN() only works on numbers

It works on anything comparable: dates, text, even times. MIN(hire_date) and MIN(last_name) are both valid, chronological order for dates, alphabetical order for text.

Best Practices

  • Use WHERE to scope MIN() to the rows that actually matter before assuming the result applies company-wide.
  • When the goal is finding which row holds the minimum, not just the value itself, reach for ORDER BY + LIMIT/TOP/FETCH FIRST instead of MIN().
  • Remember MIN() works on dates and text, not only numeric columns.

Interview Questions

What's the difference between SELECT MIN(salary) FROM employees and SELECT first_name, salary FROM employees ORDER BY salary ASC LIMIT 1?

MIN(salary) returns just the number, the lowest salary value, with no indication of who earns it. The ORDER BY + LIMIT version returns the full row, including first_name, for the employee with that lowest salary. They can return related information, but they answer different questions, one is a pure aggregate, the other is row selection.

Can MIN() be used on a date column, and what does 'smallest' mean in that context?

Yes. Dates have a natural chronological order, so MIN(hire_date) returns the earliest date in the column, the furthest back in time, exactly the same comparison logic as numbers, just applied to a different type.

Summary

MIN() returns the smallest value in a column, numeric, text, or date, and like every aggregate function it ignores NULLs and returns a single summarized value, not a full row. Finding which row holds that value requires ORDER BY and LIMIT instead.

What's Next?

The next lesson covers MAX(), MIN()'s counterpart, finding the largest value in a column.

</>

Ready to Practice SQL?

Write and run real SQL queries online, right in your browser, no install or signup required. Pick a playground based on which database you want to practice on.

SQLite / PostgreSQL

Fast, no server, no ads.

Open DB Fiddle ↗

MySQL / SQL Server

Switch databases with one dropdown.

Open SQL Fiddle ↗

Both open a third-party SQL playground in a new tab. External site terms and privacy policy apply.