I am having 2 tables.
Table 1:-
id name
1 k
2 a
Table 2:-
id sub1 sub2
1 10 20
2 30 40
I want the output as k -> 30 and a -> 70.
I fired the following query….
SELECT tbl_1.`name` , SUM(tbl_2.sub1 + tbl_2.sub2) as total
from tbl_1, tbl_2 WHERE tbl_1.id = tbl_2.id;
OUTPUT :-
k -> 100
but i want like
k->30
a->70
if anyone has any idea please kindly help….
Remove the
SUM(), and just usetbl_2.sub1 + tbl_2.sub2.SUM()sums ‘vertically’, by summing the values of all the rows.+sums ‘horizontally’ in this case, by summing the values of the columns.The way you were doing it summed both horizontally and vertically.