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 8361923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:48:58+00:00 2026-06-09T11:48:58+00:00

i am joining two tables: accn_demographics and accn_payments . The relationship between the two

  • 0

i am joining two tables: accn_demographics and accn_payments. The relationship between the two tables is one to many between accn_demographics.accn_id and accn_payments.accn_id

My question is when I am summing the PAID_AMT and COPAY_AMT, I am getting double/triple/quadrouple the number that I should be getting.

Is there an obvious problem with my join condition?

select sum(p.paid_amt) as SumPaidAmount
    , sum(p.copay_amt) as SumCoPay
    , p.pmt_date
    , d.load_Date
    , p.ACCN_ID
from  accn_payments p
join 
(
    select distinct load_date, accn_id 
    from accn_demographics
) d
    on p.ACCN_ID=d.ACCN_ID
where p.POSTED='Y'
    and p.pmt_date between '20120701' and '20120731'
group by p.pmt_date, d.load_Date,p.ACCN_ID
order by 3 desc

thanks so much for your guidance.

  • 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-09T11:48:59+00:00Added an answer on June 9, 2026 at 11:48 am

    You need to do the summation in a subquery:

    select sum(p.SumPaidAmount) as SumPaidAmount, sum(p.SumCoPay) as SumCoPay,
           p.pmt_date, d.load_Date, p.ACCN_ID
    from  (select accn_id, p.pmt_date, sum(paid_amt) as SumPaidAmt,
                  sum(copay_amt) as SumCoPay
           from accn_payments p
           where p.POSTED='Y' and
                 p.pmt_date between '20120701' and '20120731'
           group by accn_id, pmt_date
          ) p join
          (select distinct load_date, accn_id from accn_demographics) d
          on p.ACCN_ID=d.ACCN_ID
    group by p.pmt_date, d.load_Date,p.ACCN_ID
    order by 3 desc
    

    Question: do you really intend for pmt_date to be in the final results? It looks like you want to remove it from both the outer SELECT and the subquery.

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

Sidebar

Related Questions

I have two tables Question and Option having one to many relationship. after fetching
My question is simple, suppose i am joining between two tables and one of
I'm having trouble with Access, when joining two tables where one of the join
I have two tables Service and Provider . Between them is a joining table
When joining two tables, what are the difference between the two blocks below and
I have a simple question regarding the dichotomy of joining two tables vs using
I have a case of Linq, where upon joining two tables, I'm getting 10
I am joining two tables 'sales/order_item_collection' and 'sales/orders' by 'order_id', so that afterward i
I have a relatively simple query joining two tables. The Where criteria can be
Im having some trouble with joining two tables. This is what my two tables

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.