To get son and all grandsons
-
parent son A B A C A D D E D F D G G I G J i blank j blank b blank c balnk I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..
-
parent son A B A C A D D E D F D G G I G J i blank j blank b blank c balnk I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..
VB.Net Developer wrote:
I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..
Very good. What have you tried so far? Plus, what database is this query in. We don't do homework for you, and we don't do your thinking for you. We do help you if you've tried something and can't get it to work. Hint - if you are using SQL Server, take a look at Common Table Expressions (CTEs) to accomplish this.
Deja View - the feeling that you've seen this post before.
-
parent son A B A C A D D E D F D G G I G J i blank j blank b blank c balnk I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..
Trying to be a bit more helpful But the solution has to do with CTEs, at least if your using SQL Server as this is not standard SQL:
with tmp(parent, son) as ( select tab.parent, tab.son from tab where tab.parent='A' union all select tmp.super, tab.son from tmp join tab on tmp.son=tab.parent
Beware of loops! In that case you need to introduce a recursion counter or a condition that restricts son<>'A'.