oracle - Connect by clause to get the top of hierarchy -


i facing issue while using connect by clause in oracle finding hierarchical data. let me give example: parent part has child part b , b has child part c. when using connect by clause able 3 levels want top level, i.e. a.

oracle has level pseudocolumn can use:

select   mytable.id,   mytable.parentid mytable level = 1 connect prior mytable.id = mytable.parentid 

to find top-level (root) value level, precede column name connect_by_root operator:

select   mytable.id,   mytable.parentid,   connect_by_root mytable.id "top level id" mytable connect prior mytable.id = mytable.parentid 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -