sql - Oracle SELECT query to find the smallest distinct delimited string -
i have below table
c1 | path --------|----------- t1 | t0/t1 t2 | t0/t1/t2 t3 | t0/t1/t2/t3 x1 | t0/x0/x1 t2 | t0/x0/x1/t2 t3 | t0/x0/x1/t2/t3 t3 | t0/y0/y1/y2/t3 y3 | t0/x0/x2/y3 y4 | t0/x0/x2/y3/y4
i need write q query or code should return smallest distinct delimited string shown below
c1 | path --------|----------- t1 | t0/t1 x1 | t0/x0/x1 t3 | t0/y0/y1/y2/t3 y3 | t0/x0/x2/y3
ex: t0/t1
substring of t0/t1/t2
, t0/t1/t2/t3
.
t0/y0/y1/y2/t3
not substring of other string. distinct.
can please me write query in oracle
try:
select t1.* table1 t1 left join table1 t2 on t1.path <> t2.path , t1.path '%'||t2.path||'%' t2.c1 null
demo: http://sqlfiddle.com/#!4/a3f87/3
| c1 | path | |----|----------------| | t1 | t0/t1 | | x1 | t0/x0/x1 | | t3 | t0/y0/y1/y2/t3 | | y3 | t0/x0/x2/y3 |
Comments
Post a Comment