Oracle - Return shortest string value in a set of rows
Posted
by Sridhar
on Stack Overflow
See other posts from Stack Overflow
or by Sridhar
Published on 2010-04-20T16:14:49Z
Indexed on
2010/04/20
16:23 UTC
Read the original article
Hit count: 208
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.
© Stack Overflow or respective owner