Finding field with longest length in a column

Lizard picture Lizard · Jul 23, 2010 · Viewed 19.4k times · Source

How do I find the field with the longest length of a specific column in a MySQL table?

Answer

fabrik picture fabrik · Jul 23, 2010

MySQL has a lot of string functions you can use:

SELECT LENGTH(col) as my_len FROM my_table ORDER BY my_len DESC LIMIT 1

More funky version (it works):

SELECT MAX(LENGTH(col)) FROM my_table