Anton Prio Hutomo
Anton Prio Hutomo

Reputation: 49

get difference value from 2 table

I have two tables named T1 and T2. Both of the tables have a column in common called balance. How can I get the difference between the two sums of the two tables.

Example:

T1

balance
-------
100
50

The sum for T1 would be 150 (100 + 50)

T2

balance
-------
100
200

The sum for T2 would be 300 (100 + 200)

So I would like the output to give me the result 150 (sumT1-sumT2).

Upvotes: 0

Views: 40

Answers (1)

TheGameiswar
TheGameiswar

Reputation: 28890

Just sum and select from tables ..

select (select ifnull(sum(balance),0) from t2)-(select ifnull(sum(balance),0) from t1) as balance

Upvotes: 1

Related Questions