I have a table "Users" and one of the column is "USERNAME". I am trying to find out the maximum length of the username by comparing all the usernames. I need this max value to use for another query. I tried
SELECT max(length(users.username)),username
FROM users group by username;
returns all the rows.
Example:
USERNAME
----------
Tara
Amyamyse
Tommy
John
I would like to get the result as below:
MAX_Length USERNAME
--------------------
8 Amyamyse
Another option:
select username, length(username) as username_length
from users
where length(username) = (select max(length(username)) from users)
This would return multiple users in case there be a tie for the longest username. If you have specific rules for breaking a tie then update your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With