Lizard Lizard - 1 year ago 85
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?

Answer Source

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); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download