Sum of two column values from two different tables


I want sum of two column values from two different tables, how can I do it using SQL?

Suppose, these are my two tables, Table 1

Id     amount      date

101    100         2018-09-03

102    200         2018-09-03

Table 2

ID      amount       Date

101     500           2018-09-03

I want the result as 

ID       amount     

101      600

Asked by:- RameshwarLate
0
: 204 At:- 10/3/2018 11:08:31 AM
sql sql server






1 Answers
profileImage Answered by:- jaya

Suppose, you have two tables as shown below

two-different-tables-sum-min.png

Then you can execute the SQL query as below to get the total Amount of each row

select Id,sum(Amount) total
from
(
    select Id,Amount
    from TestTable1
    union all
    select Id,Amount
    from TestTable2
) t
group by Id

Output:

output-sum-two-tables-columns.png

It should work.

2
At:- 10/3/2018 2:56:43 PM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use