Not tested but give it a try:
select t1.child_par,t2.child_par
from test t1
,test t2
,test_rel tr
where tr.childkkey=t1.child_par_key
and tr.parent_key=t2.child_par_key
Frage
We have a table named test have both parent and child level information. The relationship between these two has been formed at another table called TEST_REL.
Could some body please help to get the Child-Parent with this.
Thanks.
CREATE TABLE TEST
( CHILD_PAR VARCHAR2(10 BYTE),
CHILD_PAR_KEY VARCHAR2(10 BYTE)
) ;
Insert into TEST VALUES (CHILD_PAR,CHILD_PAR_KEY) values ('CHILD1','CHILD1KEY');
Insert into TEST values (CHILD_PAR,CHILD_PAR_KEY) values ('CHILD2','CHILD2KEY');
Insert into TEST VALUES (CHILD_PAR,CHILD_PAR_KEY) values ('CHILD3','CHILD3KEY');
Insert into TEST VALUES (CHILD_PAR,CHILD_PAR_KEY) values ('CHILD4','CHILD4KEY');
Insert into TEST VALUES (CHILD_PAR,CHILD_PAR_KEY) values ('PAR1','PAR1KEY');
Insert into TEST VALUES (CHILD_PAR,CHILD_PAR_KEY) values ('PAR2','PAR2KEY');
COMMIT;
CREATE TABLE TEST_REL
( CHILDKEY VARCHAR2(10 BYTE),
PARENT_KEY VARCHAR2(10 BYTE)
)
Insert into TEST_REL VALUES (CHILDKEY,PARENT_KEY) values ('CHILD1KEY','PAR1KEY');
Insert into TEST_REL VALUES (CHILDKEY,PARENT_KEY) values ('CHILD2KEY','PAR1KEY');
Insert into TEST_REL VALUES (CHILDKEY,PARENT_KEY) values ('CHILD3KEY','PAR2KEY');
Insert into TEST_REL VALUES (CHILDKEY,PARENT_KEY) values ('CHILD4KEY','PAR2KEY');
COMMIT;
Output
CHILD1 PAR1
CHILD2 PAR1
CHILD3 PAR2
CHILD4 PAR2
Lösung
Not tested but give it a try:
select t1.child_par,t2.child_par
from test t1
,test t2
,test_rel tr
where tr.childkkey=t1.child_par_key
and tr.parent_key=t2.child_par_key