Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do you solve this join issue...
Message
From
12/04/2002 13:22:59
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How do you solve this join issue...
Miscellaneous
Thread ID:
00644420
Message ID:
00644420
Views:
50
Hi All,

I have a query where I want to sum() data from three tables. Heres the problem though. I have a 'parent' record which has some values in it, then two child tables...

So, if I do my first query:

SELECT sum(rgcur) from py_ehmast
GROUP BY ee_id

I get the correct value. Then I add the child table..

SELECT sum(m.rgcur), sum(t.tax_cur)
FROM py_ehmast m
JOIN py_ehtax t ON m.ehmast_id = t.ehmast_id
GROUP BY ee_id

Now, I get the correct tax_cur sum, but the m.rgcur sum is overstated.

Then when I add the third table...

SELECT sum(m.rgcur), sum(t.tax_cur), sum(h.hours)
FROM py_ehmast m
JOIN py_ehtax t ON m.ehmast_id = t.ehmast_id
JOIN py_ehhour h on m.ehmast_id = h.ehmast_id
GROUP BY ee_id

Of course, I get even different numbers... I know WHY this is happening, I am wondering what the easiest way to solve this is, without doing three selects?

Thanks,
BOb
Next
Reply
Map
View

Click here to load this message in the networking platform