简体   繁体   中英

ms access left join outputting more records than in left table

I have the following ms access query that reports all the records in the left table as espected. however as soon as i have a column in the select statement from the right table then the records start increasing more than the max records in the left table

can someone please assist how i can alter the code so it allows me to include fields from the right side table as well whilst keeping the max records output to be the total records in the left table an no others

SELECT BENEFITS_FORECAST2.lob, BENEFITS_FORECAST2.period, 
BENEFITS_FORECAST2.rd_aflc_f, 
(BENEFITS_FORECAST2.ils_aflc_f-ils_aflc_a) AS ils_aflc_v

FROM BENEFITS_FORECAST2 left join Benefits_mom_data_set1 ON (BENEFITS_FORECAST2.LOB = Benefits_mom_data_set1.BenefitsLOB) AND (BENEFITS_FORECAST2.PERIOD = Benefits_mom_data_set1.Period)

WHERE (((Benefits_mom_data_set1.newCnt)=1) AND ((Benefits_mom_data_set1.legalServiceProviderType) Like 'on panel'))
group by BENEFITS_FORECAST2.lob, BENEFITS_FORECAST2.period, BENEFITS_FORECAST2.rd_aflc_f 
order by BENEFITS_FORECAST2.lob, BENEFITS_FORECAST2.period

Can you share some data on both tables? Adding columns from the right should not increase the number of records on the left in a normal left join. However, I'm noticing that you you have a GROUP BY clause. If you aren't group by properly with the additional columns from Benefits_mom_data_set1, then you are likely get multiple rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM