What is MIN and MAX on a string column?
SQLLevel: FoundationAggregations Basics
What is MIN and MAX on a string column?
Hints
- Define one output row and the source-table keys.
- Check duplicates, NULLs and the order of filtering and aggregation.
Answer
MIN and MAX work on any orderable type, including strings. On strings, they return the lexicographically first and last values (alphabetical order based on the collation).
SELECT MIN(name), MAX(name) FROM employees;
-- Returns 'Aaron' and 'Zoe' (or whatever is alphabetically first/last)
Source and licence: SQL Interview Questions — Arda Kocadoru · MIT