Example:
SELECT partnumber, manufacturer, condition, SUM(qty), AVG(price), description FROM parts
WHERE [something]
GROUP BY partnumber, manufacturer, cond
MAX(LENGTH(description)) returns length of longest value in Description column.
It seems i answered my own question, MAX(description) seems to work just fine.
ORDER BY LENGTH(description) DESC LIMIT 1
This will sort the results from longest to shortest and give the first result (longest.)
Try ORDER BY LENGTH(description) DESC
and use LIMIT 1
to only get the largest.
SELECT partnumber, manufacturer, `condition`, SUM(qty), AVG(price), description
FROM parts
WHERE [something] AND LENGTH(description) = (
SELECT MAX(LENGTH(description))
FROM parts AS p
WHERE p.partnumber = parts.partnumber
AND p.manufacturer = parts.manufacturer
AND p.condition = parts.condition
)
GROUP BY partnumber, manufacturer, `condition`