Click here to Skip to main content
12,302,764 members (72,056 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-Server
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 12-Oct-12 2:11am
Comments
damodara naidu betha 12-Oct-12 9:40am
   
do u need COUNT(licensecount) or SUM(licensecount)?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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

But try as shown below by replaceing proper foreign keys.

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

Thanks
Milind
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

you have not provide some table data & sql-Query.

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

Happy Coding!
Smile | :)
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160530.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100