Oracle - Return shortest string value in a set of rows
- by Sridhar
Hi, 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?
BTW, 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
Thank you.