On Wed, 2002-11-06 at 14:39, Brent Baisley wrote: > SELECT MAX(LENGTH(column)) FROM db
Thx Brent! This works perfectly! > That will give you the length of the longest string but won't tell you > what the value is. To get the value also, you could do something like > this, but I think there should be a better way: > SELECT MAX(LENGTH(column)) AS length,column FROM db GROUP BY column > ORDER BY length LIMIT 1 I had to edit this little bit because it returned the shortest string... Here's what works for me: SELECT MAX(LENGTH(column_name)) AS length,column_name FROM table_name GROUP BY column_name ORDER BY length DESC LIMIT 1; So the 'db' in your suggestion has been replaced by the table_name and I added the 'DESC' to get the longest string! Thx again! > That query could get very slow on large databases since it can't use an > index and traverses the entire database. Luckily the db is not that big at the moment ( only 3157 records)... > On Wednesday, November 6, 2002, at 07:29 AM, Mertens Bram wrote: > > > How can I find the longest string in a column? > > > > I would like to have the value and the length of the string if this is > > possible. Is this possible or should I try to write the PHP-script? -- # Mertens Bram "M8ram" <[EMAIL PROTECTED]> Linux User #249103 # # Red Hat Linux 7.3 KDE 3.0.0-10 kernel 2.4.18-3 i686 128MB RAM # --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php