ms access - SQL only returns sum for ids with multiple occurences -


so have 3 tables (acdd, ah, life) multiple amounts per customer. customer can have combination of types. created query each table sum amounts of each acdd, ah , life. created fourth query combining of them together. problem getting ids 3 queries have in common...a customer might have life , no acdd or ah--this id missing fourth query. doing wrong?

query table(the same query exists each of 3 tables):

select distinctrow [customers-personal].[customer id],         sum([newb-coverage: ah].[ah monthly benefit]) [sum of ah monthly benefit] [customers-personal] inner join [newb-coverage: ah]  on [customers-personal].[customer id] = [newb-coverage: ah].[customer id] group [customers-personal].[customer id]; 

4th query (combining all)

select [customers-personal].[customer id],         sum_acdd.[sum of acdd amount],         sum_ah.[sum of ah monthly benefit],         sum_life.[sum of decr life amount],         sum_life.[sum of level life amount] sum_life inner join                (sum_ah inner join                        (sum_acdd inner join [customers-personal]                                  on sum_acdd.[customer id] = [customers-personal].[customer id])                        on sum_ah.[customer id] = [customers-personal].[customer id])                on sum_life.[customer id] = [customers-personal].[customer id]; 

you need use left (or right) joins. inner joins require matching records exists in tables. left join specifies all records left table should returned. rows not match in right table, null values returned. (a right join same thing swaps relative positions of table names. common practice order tables such use left joins, it's not requirement.)

see left join, right join operations specific ms access.

redo of 4th query. lazily used right joins keep original ordering of tables:

select [customers-personal].[customer id],         sum_acdd.[sum of acdd amount],         sum_ah.[sum of ah monthly benefit],         sum_life.[sum of decr life amount],         sum_life.[sum of level life amount] sum_life right join            (sum_ah right join                (sum_acdd right join [customers-personal]                          on sum_acdd.[customer id] = [customers-personal].[customer id])                on sum_ah.[customer id] = [customers-personal].[customer id])            on sum_life.[customer id] = [customers-personal].[customer id]; 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -