Professional Web Applications Themes

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. #1

    Default 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. #2

    Default 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. #3

    Default 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

Similar Threads

  1. Replies: 4
    Last Post: March 22nd, 12:58 AM
  2. Select, Join & field values - 2 tables
    By Justin Koivisto in forum MySQL
    Replies: 3
    Last Post: February 13th, 08:06 PM
  3. Using INSERT with Multiple Tables
    By Tim Mannah in forum Dreamweaver AppDev
    Replies: 4
    Last Post: May 18th, 06:44 PM
  4. update multiple records in multiple tables from one form
    By Anj01 in forum Coldfusion Database Access
    Replies: 1
    Last Post: May 17th, 05:54 AM
  5. find values in two tables, display results in one
    By Joseph O'Brien in forum FileMaker
    Replies: 1
    Last Post: September 18th, 09:58 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139