Shouldn't the parent table be included?
SELECT B.C1
FROM PARENT A,
CHILD B
WHERE A.P1 = B.P1
AND A.P2 = B.P2
AND A.P3 = B.P3
AND A.C1 = your value of C1;
------------------------------
Rupali Wagle (she/her/hers)
Principal Technical Support Engineer
Rocket Software, USA
T: +1 781 577 4493 (W) +1 713 444 2877 (C)
Support: +1 855 577 4323
E:
rwagle@rocketsoftware.comW:RocketSoftware.com
------------------------------
Original Message:
Sent: Mon November 28, 2022 04:37 AM
From: Christian Lenke
Subject: How to Retrieve Child Table's "Siblings"
If I am seeing it right your siblings have the same parent. You could do a join like this
SELECT B.C1FROM CHILD A, CHILD BWHERE A.P1 = B.P1 AND A.P2 = B.P2 AND A.P3 = B.P3 AND A.C1 = <your identified child>;
Additionally, recursive SQL often is a good idea to determine hierarchical / forein key relationships across tables. Not required here, but perhaps you have more requirements. Examples: BOM of course, but also products to top-categories (via sub, sub-sub etc. categories) and many more. Lots of examples exist on the web.
------------------------------
Christian Lenke
Original Message:
Sent: Fri November 25, 2022 09:33 AM
From: Curt Gilker
Subject: How to Retrieve Child Table's "Siblings"
I have two tables, call them 'Parent' and 'Child.' The primary key of Parent (columns P1, P2, and P3) is foreign key on Child. Child's primary key is (P1, P2, P3, and C1).
Given a value for C1, how can I query all of the other rows on the Child table with the same Parent?
------------------------------
Curt Gilker
------------------------------
#Db2forz/OS