Query to display the name of the user(s) having the longest name, sorted by the name of the user. Please note that there may be leading or trailing spaces in the names of the users.
I tried the following query:
select name, max(length(trim(name))) as length
from user
group by name
order by name;
but it gives me the length of all the values of the name
column without spaces.
But I need only those values which have maximum length.
Suppose there are 15 names in the column and there are 5 names which are of longest length, so all those 5 names and corresponding length.
Table name: user
Column name and datatype:
name varchar(255)
select name from user where length(name) = (select max(length(name)) from user) order by name;
this worked for me !!