I have 2 tables. Customer and customer_parent_hierarchy.
customer table contains
customer_key
customer_number
example customer
100 00001
101 00002
102 10002
customer_parent_hierarchy table contains
customer_key
parent_key
example customer_parent_hierarchy
100 102
101 100
102 102
what I want the sql to do is output the following
customer_key customer# parent_Key parent#
100 00001 102 10002
101 00002 100 00001
102 10002 102 10002
The query I've been working on dosent quite work
Code:
select p.parent_key, p.parent_number, c.customer_key, c.customer_number
from
(select cc.CUSTOMER_NUMBER as parent_number, ccph.PARENT_CUSTOMER_KEY as parent_key
from CD_CUSTOMER cc, CD_CUSTOMER_parent_hierarchy ccph
where
ccph.HIERARCHY_TYPE = '-' and
ccph.PARENT_CUSTOMER_KEY = cc.CUSTOMER_KEY) p,
(select cc.CUSTOMER_NUMBER as customer_number, ccph.CUSTOMER_KEY as customer_key
from CD_CUSTOMER cc, CD_CUSTOMER_parent_hierarchy ccph
where
ccph.HIERARCHY_TYPE = '-' and
ccph.CUSTOMER_KEY = cc.CUSTOMER_KEY) c
Thanks for helping.