Lizard Lizard - 2 months ago 7x
MySQL Question

Finding field with longest length in a column

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


You can use the mysql command LENGTH()

$q = mysql_query("SELECT LENGTH(yourfield) AS fieldlength FROM yourtable ORDER BY fieldlength DESC LIMIT 1"); 
echo $longestfield = mysql_result($q,0);