HackerRank MySQL - Weather Observation Station 5



Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.



  1. SELECT *
  2. FROM
  3. (SELECT CITY, LENGTH(CITY)
  4. FROM STATION
  5. ORDER BY LENGTH(CITY), CITY)
  6. WHERE ROWNUM = 1
  7. UNION
  8. SELECT *
  9. FROM
  10. (SELECT CITY, LENGTH(CITY)
  11. FROM STATION
  12. ORDER BY LENGTH(CITY) DESC, CITY)
  13. WHERE ROWNUM = 1;

download android app