General information
Forum:
Microsoft SQL Server
Title:
How do you solve this join issue...
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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only