# Add values from multiple tables - MySQL

This could be really simple...but I just can't seem to work it out so any help is gratefully received. I have several tables of equal dimensions, each full of numbers. What I am trying to do is create a new table that presents combined totals. ======== Table One ======== 1 | 2 | 3 -------- 4 | 5 | 6 ======== Table Two ======== 0 | 2 | 4 -------- 6 | 8 | 0 The result would be 1 | 4 | 7 ---------------- 10 | 13 | 6 Sure this is easy so if someone could point me ...

1. ## Add values from multiple tables

This could be really simple...but I just can't seem to work it out so
any help is gratefully received.

I have several tables of equal dimensions, each full of numbers. What
I am trying to do is create a new table that presents combined totals.

========
Table One
========
1 | 2 | 3
--------
4 | 5 | 6

========
Table Two
========
0 | 2 | 4
--------
6 | 8 | 0

The result would be

1 | 4 | 7
----------------
10 | 13 | 6

Sure this is easy so if someone could point me in the right direction,
that would be great.

Dan

Devon_Dan Guest

2. ## Add values from multiple tables

This could be really simple...but I just can't seem to work it out so
any help is gratefully received.

I have several tables of equal dimensions, each full of numbers. What
I am trying to do is create a new table that presents combined totals.

========
Table One
========
1 | 2 | 3
--------
4 | 5 | 6

========
Table Two
========
0 | 2 | 4
--------
6 | 8 | 0

The result would be

1 | 4 | 7
----------------
10 | 13 | 6

Sure this is easy so if someone could point me in the right direction,
that would be great.

Dan

Devon_Dan Guest

3. ## Re: Add values from multiple tables

On Jul 21, 10:57 am, Devon_Dan <com> wrote:

The problem is that you don't seem to have any condition on which to
join the two tables. In other words, given a row in Table One, how do
I know which row in Table Two to add to it? Hint: the "row number" is
not the right answer since there really isn't such a concept without
specifying a column to sort by.

Once you figure that out it should be trivial. Suppose the two tables
have a common field called "id." Your query would then look like
this:

select t1.a + t2.a as a,
t1.b + t2.b as b,
t1.c + t2.c as c
from table1 t1
join table2 t2
on t1.id = t2.id

ZeldorBlat Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•