Suppose, I have a table Station
in SQL Server:
| ID | Name |
+------+------+
| 1 | a |
| 2 | b |
| 3 | cc |
| 4 | ddd |
| 5 | eee |
I want to retrieve shortest and Longest name along with length (in case of a tie, it will show alphabetically top 1) so, the output will be
| a | 1 |
+-----+------+
| ddd | 3 |
I tried this:
Select
Name, len(name)
from
Station
where
len(name) = (Select min(len(name)) from Station)
union
Select
Name, len(name)
from
Station
where
len(name) = (Select max(len(name)) from Station)
But, I have to take the alphabetically first only which I am not able to do