top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I find the longest value in my mysql table?

0 votes
499 views
How can I find the longest value in my mysql table?
posted Jun 18, 2014 by Sachin Dahda

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

SELECT * FROM table
WHERE LENGTH(column) = ( SELECT MAX(LENGTH(column)) FROM table )

answer Jun 18, 2014 by Noor Muhammad
0 votes

The LENGTH() function applied to a field name will return the length of that field.

So all you need is the relevant query to find the length of the longest item in a field like so:

<?php
$p = mysql_query("SELECT LENGTH(firstname) AS thelength FROM myfriends ORDER BY thelength DESC LIMIT 1");

$longestname = mysql_result($p,0,0);    

echo "The longest first name is $longestname letters long!"; 
?> 
answer Jun 18, 2014 by Karamjeet Singh
Similar Questions
+5 votes

How can I insert the content of excel file into MySQL Table, any pointer?

0 votes

How can I insert data into one table from two other tables where i have three tables namely users, role and userrole.
Now I want to insert the data into userrole table from users table and role table with a single statement.

0 votes
for($i=0;$i<=feof($getdata);$i++)
{
if (filter_var($data[$i][1], FILTER_VALIDATE_EMAIL)){
echo $data[$i][1];
$email=$data[$i][1];
$conn = mysqli_connect($dbhost,$dbuser,$dbpass, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
$sql ="INSERT INTO promo_user (uid,name,email) VALUES (,'', '$email')";
mysqli_query($sql,$conn);
mysqli_close($conn);

I am using the above code but there is something wrong with it,whenever i run the code the echo is working fine but the content does go into sql table

Please help

...