I'm trying to write a query that returns the shortest string value in the column. For ex: if ColumnA has values ABCDE, ZXDR, ERC, the query should return "ERC". I've written the following query, but I'm wondering if there is any better way to do this?
The query should return a single value.
select distinct ColumnA from
(
select ColumnA, rank() over (order by length(ColumnA), ColumnA) len_rank
from TableA where ColumnB = 'XXX'
)
where len_rank <= 1
How about:
select ColumnA
from
(
select ColumnA
from tablea
order by length(ColumnA) ASC
)
where rownum = 1
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