If I say:
select max(length(Name))
from my_table
I get the result as 18, but I want the concerned data also. So if I say:
s
select *
from my_table
where length( Name ) = (
select max( length( Name ) )
from my_table
limit 1
);
It this involves two table scans, and so might not be very fast !
Ok, I am not sure what are you using(MySQL, SLQ Server, Oracle, MS Access..) But you can try the code below. It work in W3School example DB. Here try this:
SELECT city, max(length(city)) FROM Customers;
Use:
SELECT mt.name
FROM MY_TABLE mt
GROUP BY mt.name
HAVING MAX(LENGTH(mt.name)) = 18
...assuming you know the length beforehand. If you don't, use:
SELECT mt.name
FROM MY_TABLE mt
JOIN (SELECT MAX(LENGTH(x.name) AS max_length
FROM MY_TABLE x) y ON y.max_length = LENGTH(mt.name)