I have a CONNECT BY hierarchal query that starts with a known child part and returns the top level parent(s). It runs quickly and works great except for one thing: it returns null values for the child part.
WITH
c AS(
SELECT
d.C_ID,
d.PART_ID
FROM T_MASTER_DAT d
WHERE
d.C_ID = 1124609156
)
SELECT DISTINCT
c.C_ID CHILD_ID,
c.PART_ID CHILD_PART,
s.C_ID_1 TOP_PARENT_ID,
d2.PART_ID TOP_PARENT_PART,
d2.CUR_FLAG TOP_PARENT_CUR_FLAG,
d2.CANCEL TOP_PARENT_CANCEL,
d2.UNIT,
d2.OPP_BR_UNIT
FROM T_MASTER_STR s
LEFT JOIN c on c.C_ID = s.C_ID_2
JOIN T_MASTER_DAT d2 on d2.C_ID = s.C_ID_1
WHERE
d2.OPP_BR_UNIT is not null and
d2.CUR_FLAG = 'y' and
d2.CANCEL = 'n'
CONNECT BY PRIOR s.C_ID_1 = s.C_ID_2
START WITH s.C_ID_2 = c.C_ID
I simplified things a bit here. In the real environment table c is the result of a few table joins so it's more complex but the gist of table c is to get that C_ID number and use it to look up the parent. I'm hoping my issue is me fundamentally not understanding how to use CONNECT BY so a reproduceable dataset isn't needed.
T_MASTER_DAT has all the part information like part ID, part name, revision, current status.
T_MASTER_STR is a structure table that links child and parent parts/assemblies.
Thank you for reading!
CREATE TABLEandINSERTstatements for your sample data; an English (not code) explnation of the logic that you are trying to implement; the issues/errors with your current solution; and the expected output for that sample data. At the moment, you have told us that something is wrong with your query but you have not explained what the inputs to the query are or what a correct answer looks like so it is impossible to answer your question.