My code is this but gives error, don’t know why. Please help!
x
select city,
min(length(city))
from station
group by length(city)=min(length(city))
order by city asc;
Advertisement
Answer
If you just want the city with the shortest name, you can simply order by
and limit
:
select city, char_length(city) city_length
from station
order by city_length
limit 1
This returns just one row. On the other hand, if you want to allow bottom ties, then you can filter with a subquery, like so:
select city, char_length(city) city_length
from station
where char_length(city) = (select min(char_length(city)) from station)