...

View Full Version : How to get the SUM value from two tables? join tables? subquery?



NinjaTurtle
01-30-2007, 09:37 AM
Hi,
I have two tables:

table A

Id. | id_result | value
1 | 1| 10
2 | 1| 11
3 | 2| 7
4 | 2| 13

table B

Id. | id_result | value
1 | 1| 4
2 | 1| 1
3 | 2| 5
4 | 2| 6


How can I get sum of unique keys from table A and B (id_result) like this?:

id_result | sum_table_A | sum_table_B
1 | 21| 5
2 | 20| 11

I can do it with UNION or 2 separate SQL statement, but how to make it in 1 query or using subquery?


Jason

guelphdad
01-30-2007, 11:21 AM
a UNION is one query and that is what you need.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum