Lizard Lizard - 4 months ago 8
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

You can use the mysql command LENGTH()

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