Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:46:23+00:00 2026-06-16T00:46:23+00:00

I have two tables set up basically like this (extremely lite version): Table 1

  • 0

I have two tables set up basically like this (extremely lite version):

Table 1:

ID       Amt 1     Amt 2
-------------------------    
112     $20        $30
112     $50        $60
125     $75        $05

Table 2:

ID       Amt 3     Amt 4
-------------------------
112       $25       $30
125       $40       $60
125      $110      $120

All the amount columns needed to be summed separately, the output to be similar to this:

Query results:

ID       Amt 1     Amt 2     Amt 3     Amt 4
--------------------------------------------
112     $70        $90       $25       $30
125     $75        $05       $150      $180

The joins I’ve tried result in the records duplicating (and summing) by a factor of the times the ID repeats in the second table. I have no primary key to connect these tables.

Any help would be greatly appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:46:24+00:00Added an answer on June 16, 2026 at 12:46 am

    On SQL Server 2005 or newer, you could use two CTE’s (Common Table Expression) to do the summing/grouping per table, and then join the two – something like this:

    ;WITH CTE1 AS
    (
        SELECT 
            ID, Amount1 = SUM(Amt1), Amount2 = SUM(Amt2)
        FROM
            dbo.SumTbl1
        GROUP BY
            ID  
    ),
    CTE2 AS
    (
        SELECT 
            ID, Amount3 = SUM(Amt3), Amount4 = SUM(Amt4)
        FROM
            dbo.SumTbl2
        GROUP BY
            ID  
    )
    SELECT CTE1.ID, Amount1, Amount2, Amount3, Amount4
    FROM CTE1
    INNER JOIN CTE2 ON CTE1.ID = CTE2.ID
    

    This gives me your desired output

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables set up in phpmyadmin- table userid and table data. The
I have set up 2 two tables - table userid and table data in
I am a bit stumped on this. Basically I have two tables: Page: id
Possible Duplicate: Retrieving the last record in each group I have two tables set
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have a MySql db with innoDB tables. Very simplified this is how two
So I have this application in ASP MVC 3. My database has two tables:
I am going to make this REALLY simple. I have two tables. public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.