Wednesday, March 28, 2012

Is this query correct

I have two tables cd_customer and cd_customer_parent_hierarchy, I want to select all those customers from the parent table that are in the child table where the seed_flag for the child key is yes but the seed_flag for the parent is no

SELECT ccph.parent_customer_key
FROM cd_customer cc,
cd_customer_parent_hierarchy ccph,
cd_customer cc_p
WHERE
ccph.customer_key = cc.customer_key AND
ccph.parent_customer_key = cc_p.customer_key AND
CCPH.HIERARCHY_TYPE = '-' AND
CC.SEED_FLAG = 'Y' AND
CC_P.SEED_FLAG = 'N'

also what would be the difference in queries if I were to add a group by ccph.parent_customer_key

Thanksquery looks okay, given the fact that we can't see your table layouts nor sample data

if you add that GROUP BY, two things happen -- the query slows down, and only unique values will be returned

No comments:

Post a Comment