Hi all, i have a table like below

Id Names

1 Sanjay, Anu, Rock
2 Mohamed, Asif, Selva, Manoj, Booker T
3 Jerrico, Cena
4 Amala

How do i select MAX LENGTH OF STRING from column in the table,

I need the result like,

2 Mohamed, Asif, Selva, Manoj, Booker T

Is there any query for that ??

Recommended Answers

All 5 Replies

Member Avatar for diafol

"SELECT id, CHAR_LENGTH(`Names`) AS maxlength ORDER BY maxlength DESC"

Hi Ardav, Thank your for reply, i applied your code it gives me an empty value. Any idea?

Member Avatar for diafol

Doh i forgot to put a table in the sql. Put

From table

After as maxlength where table is your tablename

Member Avatar for diafol

Like?

SELECT id, CHAR_LENGTH(`Names`) AS maxlength FROM table

Should be the bare minimum to display id, maxlength

SELECT id, CHAR_LENGTH(`Names`) AS maxlength FROM table ORDER BY maxlength DESC, `Names` LIMIT 1

Will get you the record with longest names field

Hi Ardav Thank you for reply. Its worked for me thank u, but little change DESC to ASC. Thank You. I Marked the thread as closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.