Paul
Paul

Reputation: 59

HOW TO USE SUM WITH INNER JOIN

Ok I have here

tbl_one
    id
    amount
tbl_two
    id
    amount

is it posible to get the sum of amount in tbl_one and tbl_two using inner join ?? can someone know how to do it ? THANKS IN ADVANCE .

Upvotes: 0

Views: 44

Answers (1)

Beartums
Beartums

Reputation: 1350

Assuming you can join on id:

SELECT a.id, sum(a.amount+b.amount) as total
      from tbl_one as a JOIN tbl_two as b
      ON a.id = b.id
GROUP BY a.id

That is also assuming that you need to group, otherwise you can drop the sum and the GROUP BY.

Upvotes: 1

Related Questions