Here is another way to do this, using the always convenient row_number analytic function:
with cte as ( select city, length(city) as len, row_number() over (order by length(city), city) as smallest_rn, row_number() over (order by length(city) desc, city) as largest_rn from station ) select city, len from cte where smallest_rn = 1 union all select city, len from cte where largest_rn = 1
sstan source share