Results 1 to 4 of 4
  1. #1
    scotty22 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jun 2011
    Posts
    29

    summing columns from two tables

    Hi there,

    I'm trying to sum up the values from two columns in two different tables using this SQL statement:

    SELECT cl.Scheme, (Sum(cl.Gross1)+ Sum(cd.Gross2)) AS SumOfGrossRes
    FROM cl INNER JOIN cd ON cl.Scheme = cd.Scheme
    GROUP BY cl.Scheme
    HAVING (((cl.Scheme)="ABC" Or (cl.Scheme)="DEF" Or (cl.Scheme)="GHI"));

    What it seems to be doing is summng the values, for a particular scheme, from both tables, then repeating this for the amount of times it appears in the second table.

    So if a scheme appears three times in the cd table then it adds the values from the first table to the second table, then repeats this another two times.

    Is there a way to prevent this?

    Kind regards,

    Scotty22

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Try changing your join from inner to left

    Alan

  3. #3
    scotty22 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jun 2011
    Posts
    29
    Doesn't change anything.

    I'm more curious to know as to why it's doing this. I can't understand why it would be designed to repeat the summation as it does.

    Kind regards,

    Scotty22

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    try changing your HAVING to WHERE

    If that doesn't work post an example database or at least show us the structure of your two tables with example data.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding columns to existing tables.
    By OrangePie in forum Access
    Replies: 1
    Last Post: 07-07-2011, 01:49 PM
  2. help with summing columns in a query
    By chrismja in forum Queries
    Replies: 0
    Last Post: 03-08-2011, 07:09 AM
  3. Replies: 8
    Last Post: 05-25-2010, 04:50 AM
  4. Replies: 3
    Last Post: 02-08-2010, 09:00 AM
  5. Replies: 1
    Last Post: 06-21-2007, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums