Link to home
Start Free TrialLog in
Avatar of vijay11
vijay11

asked on

Can some one help with this Sql

I have a table 'a' like this

parent     child  

9          10
9         11       
                                             
I have a table 'b' like this

ID       primary_id       primary_name          type  
 
1            9            cal              big      
1            9            cal              small            
2            9            cal              big      
2            9            cal              small      
4            10            Nev            small                        
4            10            Nev            big
3               16            Ill                big      
I want the output like this ( For the primary_id in table 'b' I want the parent of and child of to be populated based
on table 'a' in the out put .

ID       primary_id       primary_name          type          parent of         child of
 
1            9            cal                               big               10                  null
1            9            cal                            small            10                  null
1            9            cal                              big                       11                  null
1            9            cal                           small                     11                  null
2            9            cal                           big                       10                  null
2            9            cal                           small                     10                  null
2            9            cal                            big                      11                  null
2            9            cal                               small            11                  null
4            10            Nev                             small            null                  9            
4            10            Nev                                big           null                  9
3               16            Ill                                   big            null                  null



Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Sharath S
Sharath S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vijay11
vijay11

ASKER

Here In the out put the number of rows  with  primary_id     9  gets double , because primary_id     9 has 2 childs in the table 'a'  ,