Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can SQL handle a Parent Child query ?

Status
Not open for further replies.

saustin

MIS
Feb 19, 2001
336
0
0
US
Hi All,
Have a parent file with a field (BASEID) that is also in a child (transaction) file many times. All records in both tables also have cost fields. What i am interested in is a case where the parent and child with the SAME BASEID do NOT have the same total costs. How do you do this in access sql ?
It's very easy to come up with the sum of the costs for several child records with the same BASEID. The problem is that an IN statement can only return one value. I need baseid and costs.
Any sql thoughts greatly appreciated ! Have looked at subquery & union help and am not sure where to go other than creating a temp table. There has to be a better way.

Thanks, Steve.
 
Does the query below solve the problem?

SELECT PARENT.BASEID, First(PARENT.COST) AS ParentCost, Sum(CHILD.COST) AS ChildCost FROM PARENT INNER JOIN CHILD ON PARENT.BASEID = CHILD.BASEID
GROUP BY PARENT.BASEID
HAVING First(PARENT.COST) <> Sum(CHILD.COST)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top