Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Query using three table

Author  Topic 

Naqibullah
Starting Member

7 Posts

Posted - 2015-02-26 : 06:14:45
Dear valued colleagues,
i have three tables i.e customer, saving, loan
customer to Saving one to many relationship
customer to loan one to many relationship
when i run query to return total savings and total loan for a specific customer it returns a wrong result although i group by customer.....please help me

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-02-26 : 12:23:53
Show us what you have so far, sample data and expected output.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Naqibullah
Starting Member

7 Posts

Posted - 2015-03-12 : 01:09:52
thanks for your reply
this is my query

SELECT Group.Group_ID, Group.Group_Name, Sum(MainTbloan.LoanAmount) AS SumOfLoanAmount, Sum(MainTblCredit.FixedSaving) AS SumOfFixedSaving
FROM (([Group] INNER JOIN Woman ON Group.Group_ID = Woman.Group_ID) INNER JOIN MainTblCredit ON Woman.Mem_ID = MainTblCredit.MemID)
INNER JOIN MainTbloan ON Woman.Mem_ID = MainTbloan.MemID
GROUP BY Group.Group_ID, Group.Group_Name
HAVING (((Group.Group_ID)=19)) OR (((Group.Group_ID)=20));

This is the result which is a wrong total for SumOfFixedSaving
Group_ID Group Name SumOfLoanAmount SumOfFixedSaving
19 Tawfiq 1359990 248090
20 Jawidan 119390 21450
Grand total 1479380 269540
Regards
Go to Top of Page
   

- Advertisement -