SQL query for finding the longest name and shortest name in a table

后端 未结 29 2018
春和景丽
春和景丽 2021-01-31 00:11

I have a table with one of the columns is of type varchar(city). and want to find the longest and shortest of values stored in that column.

select a.city, a.city         


        
29条回答
  •  醉话见心
    2021-01-31 00:21

    length(CITY) will return the length of the string,

    https://www.w3schools.com/sql/func_mysql_length.asp

    (select CITY, length(CITY) from STATION order by length(CITY),CITY limit 1)
    UNION
    (select CITY, length(CITY) from STATION order by length(CITY) DESC limit 1);
    

提交回复
热议问题