Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have a master table and detail table.Corresponding to an ID in master i will have 2/more rows in detail table. Based on the ID of detail i have values in another table say table3. That means if i have 2 rows in detail i will have 2 rows in table3. There is a field licensecount in table 3 and both rows wil have same values for that column. I need to find count of that licensecount based on the id in the mastertable.


The problem is when i join these table and take SUM(table3.licensecount) i ger the duplicate values added as result. For ex: if the licensecount is 20 what i get is 40 where i should be getting is 20..


Can anyone pls help me out. Thanks in advance
Posted
Comments
damodara naidu betha 12-Oct-12 9:40am    
do u need COUNT(licensecount) or SUM(licensecount)?

There is very less data provided and question is little vague.

But try as shown below by replaceing proper foreign keys.

SQL
select count(licensecount) from
table1,table2,table3
where
table2.sameid= table3.sameid
and table2.id = table1.id


Thanks
Milind
 
Share this answer
 
you have not provide some table data & sql-Query.

try distinct
or
check type of join & conditions applied for join.

Happy Coding!
:)
 
Share this answer
 
Comments
Arjun Menon U.K 12-Oct-12 8:31am    
Sorry Aarti i dont have any data my friend just texted this and i couldn't find a solution
Aarti Meswania 12-Oct-12 8:34am    
it's ok.
then suggest this to solve query

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900