I'm trying to solve a question in HackerRank called "Your Weather Observation Station 5", the question asks to return the shortest and longest city names within the provided table.
Demonstration to clarify my confusion:
SELECT MIN(City) FROM STATION;
Output: A name of city with 4 characters.
SELECT MIN(LEN(City)) FROM STATION;
Output: 3.
Why the MIN() function output isn't a city name with 3 characters? I would appreciate an explanation of this behavior.
CodePudding user response:
When you "MIN" a string column, you will get the alphabetically first listing. It has nothing to do with the length of the string.
Example, "Albuquerque" appears alphabetically before "Miami".