Avatar of SPLady
SPLady asked on

Why am I getting duplicates on this outer join?

Hi experts!  why am i get duplicates with this outer join and what can i do to eliminate them?
SELECT     AVG(vPlanJoin_InvoiceOrder.Order_Plan) AS Order_Plan, AVG(vPlanJoin_InvoiceOrder.Invoice_Plan) AS Invoice_Plan, 
                      SUM(vReportdataCurrentPrior.OrderAmount_LastYear) AS OrderAmount_LastYear, SUM(vReportdataCurrentPrior.InvoiceAmount_LastYear) 
                      AS InvoiceAmount_LastYear, SUM(vReportdataCurrentPrior.OrderAmount_CurrentYear) AS OrderAmount_CurrentYear, 
                      SUM(vReportdataCurrentPrior.InvoiceAmount_CurrentYear) AS InvoiceAmount_CurrentYear, vReportdataCurrentPrior.subProduct, 
                      vPlanJoin_InvoiceOrder.Plan_Month, vReportdataCurrentPrior.site
FROM         vPlanJoin_InvoiceOrder RIGHT OUTER JOIN
                      vReportdataCurrentPrior ON vPlanJoin_InvoiceOrder.recType = vReportdataCurrentPrior.recType AND 
                      vPlanJoin_InvoiceOrder.Plan_Year = vReportdataCurrentPrior.transyear AND 
                      vPlanJoin_InvoiceOrder.Plan_Month = MONTH(vReportdataCurrentPrior.transDate) AND 
                      vPlanJoin_InvoiceOrder.SubProduct = vReportdataCurrentPrior.subProduct
GROUP BY vReportdataCurrentPrior.subProduct, vPlanJoin_InvoiceOrder.Plan_Month, vPlanJoin_InvoiceOrder.EnergyOrg, vReportdataCurrentPrior.site
HAVING      (vPlanJoin_InvoiceOrder.Plan_Month = 11)
ORDER BY vReportdataCurrentPrior.site

Open in new window

Microsoft SQL Server 2005

Avatar of undefined
Last Comment
8080_Diver

8/22/2022 - Mon
SOLUTION
BrandonGalderisi

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
8080_Diver

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes