MIN, MAX and Non-Numeric Aggregation
Aggregating dates and strings, and the meaning of MIN over text.
MIN and MAX Beyond Numbers
Candidates assume MIN and MAX only work on numbers. Interviewers love to ask: "What does MAX(name) return? What about MIN(order_date)?"
The truth: MIN and MAX work on any orderable type — numbers, dates, and strings. Understanding the ordering rules for each type is the real skill being tested here.
The Numeric Case
Start with the familiar. On numeric columns, MIN returns the smallest value and MAX the largest. Simple.
Like the other aggregates, MIN and MAX ignore NULLs. A NULL is never the minimum or maximum; it is simply skipped. If every value is NULL, both return NULL.
SELECT MIN(salary) AS lowest, MAX(salary) AS highest
FROM employees;All lessons in this course
- COUNT(*) vs COUNT(column) vs COUNT(DISTINCT)
- SUM and AVG with NULLs
- MIN, MAX and Non-Numeric Aggregation
- Aggregates Without GROUP BY