Find longest string in a column

I had been looking for ways to select the longest string record of a column in a database, may I know is there a sql query for it ?
such as looking up the person that has the longest name
Abdullah Ahmad Badawi

Thank you.

select name from daTable
where length(name) =
( select max(length(name)) from daTable )

Thank you, that’s good one, but how about the record that has the most number of words ? I am referring to MYSQL manual now, but still can’t find a solution for this. Thank you.

here’s an idea

compare LENGTH(name) and LENGTH(REPLACE(name,’ ‘,’'))

the difference is the number of spaces removed

find the max of that


I was wondering why you all have such a good idea, does this idea comes naturally or because you have experienced it before from somewhere else ? I would like to improve my logic skills. Got any advice for me ? Thanks.

it comes from practice, practice, practice


Just in case if anyone like to know the solution,
SELECT lemma FROM word WHERE (LENGTH(lemma)-LENGTH(REPLACE(lemma,’ ‘,’‘)))=(SELECT MAX(LENGTH(lemma)-LENGTH(REPLACE(lemma,’ ‘,’'))) FROM word);

very nice :slight_smile:

Yeah, you are right, it comes from practice, practice, practice, practice, and even more practice. :slight_smile:

wanna know a really good way to practice?

start answering questions on database forums


Yeah…Thanks, I would allowed some of my time to do it even I am very busy with my own stuff.