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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Query using three table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Naqibullah
Starting Member

Afghanistan
7 Posts

Posted - 02/26/2015 :  06:14:45  Show Profile  Reply with Quote
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

USA
38200 Posts

Posted - 02/26/2015 :  12:23:53  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

Afghanistan
7 Posts

Posted - 03/12/2015 :  01:09:52  Show Profile  Reply with Quote
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

Edited by - Naqibullah on 03/14/2015 23:21:40
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000