• It's a tree or hierarchy, whatever you prefer.

    I guess, you will need to use some sort of recursive CTE. Hard to say anything more based on provided limited details.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]