i-CONICA
i-CONICA

Reputation: 2379

Simple MySQL query not working as hoped

I'm running this query, I need to find out the longest string in a given field, so I can make sure it doesn't wrap when displayed on the front-end.

#The query is:
SELECT MAX(CHAR_LENGTH(fullname)), fullname FROM soft_data;

What I expected was something like: 58 "string of 58 character length"

What I got was:41 "string of 27 character length"

max(char_length(fullname)), fullname
41  Zoom Player Professional 7

I hope I've explained well enough.

Thanks.

Upvotes: 0

Views: 55

Answers (2)

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115520

SELECT CHAR_LENGTH(fullname)
     , fullname 
FROM soft_data
ORDER BY CHAR_LENGTH(fullname) DESC
LIMIT 1

Upvotes: 2

user359040
user359040

Reputation:

Add order by CHAR_LENGTH(fullname) desc to the end of your query.

Upvotes: 2

Related Questions