Quantcast
Channel: SCN: Message List - SAP Adaptive Server Enterprise (SAP ASE) for Custom Applications
Viewing all articles
Browse latest Browse all 3587

how to retrieve tree data with one sql query with sybase ase 12.5?

$
0
0

suppose I have a tree data stored in mytab with id, parentid,

then I want to get all parents for each id in one query.

For example, a binary tree like(node 1 parent is null):

               1

        11          12

   

    111    112   121   122

 

 

for any node, find out all parents with parent level(from bottom to top).

for example, node 111:  I want to have data like:

    id parentid level

    111    11       1   

    11     1        2

 

for node 11, I want to have data like:

    id parentid level

    111    11       1   

 

for node 121, I want to have data like:

    id parentid level

    121    12       1   

    12     1        2

 

and so on.

 

Without cursor with loop(cursor with very bad performance for this case), how to get it in one query(maybe a recursive query)?


Viewing all articles
Browse latest Browse all 3587

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>