MIN and MAX return the extreme value of a column across matching rows. They work beyond numbers: MIN(hire_date) is the earliest hire, MAX(name) the alphabetically last name. One caveat: aggregates collapse rows, so “the value” is easy but “WHO has it” needs an ORDER BY … LIMIT 1 follow-up (or a window function).
--how it works
1
Extremes of a column
MIN(salary), MAX(salary) — one scan, both answers.
2
They work beyond numbers
Dates: earliest/latest; text: alphabetically first/last — comparisons follow the type.
3
Scope with WHERE
Extremes within a slice: MAX(salary) WHERE department = 'Sales'.
4
Group for per-bucket extremes
GROUP BY department + MAX(salary) = the top salary in each team.
5
The owner needs a follow-up
Aggregates collapse rows, so "WHO has the max" needs ORDER BY … DESC LIMIT 1 — or a window function.
--visualization
WHERE department =
maximum minimum others
Stage 1 / 8
MIN(salary) and MAX(salary) over the whole table.
--example
query.sql
1SELECTMIN(salary)ASlowest,
2MAX(salary)AShighest
3FROMemployees;
Result
lowest
highest
47000
91000
David holds the floor (47k), Cynthia the ceiling (91k) — spread of 44k. Crown and flag the bars in the visualization.
--variants
MIN & MAX together
The full spread in one query.
query.sql
1SELECTMIN(salary)ASlowest,MAX(salary)AShighest
2FROMemployees;
Result
lowest
highest
47000
91000
1David holds the floor at 47000.
2Cynthia holds the ceiling at 91000.
3Spread: 44000 — the range your salary bands must cover.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses →Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free →Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books →