0

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 ??

2
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by mohamedasif18
0

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

Edited by diafol

0

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

Edited by mohamedasif18

0

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

From table

After as maxlength where table is your tablename

0

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

Edited by diafol

0

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.

Edited by mohamedasif18

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.