i'm trying to find the longest text in my column row DNAME. i have succeded in doing so but i cant seem to show the longest text only the ammout of length:
SELECT MAX(CHAR_LENGTH(DNAME)) as 'Max length' FROM DEPT;
this will give the answer
+------------+ | max length | +------------+ | 10 | +------------+
what i want to show is
+--------------+--------------+ | DNAME | Max LENGTH | +--------------+--------------+ | ACCOUNTING | 10 | +--------------+-------------- i tried with:
SELECT DNAME, MAX(CHAR_LENGTH(DNAME)) as 'Max length' FROM DEPT HAVING MAX(CHAR_LENGTH(DNAME));
(this will only give the first DNAME in the column row, not the one with the longest length and the max length totally in the column row)
and
SELECT DNAME as 'Max length' FROM DEPT HAVING MAX(CHAR_LENGTH(DNAME));
(this wil only give the first DNAME in the column row and not the one with the longest length)