SQLTeam.com | Weblogs | Forums

Query data not tying out

Hello all

I have written two short and basic queries that should tie, but for some reason they do not for some reason. Here is the first simple query. With this query I get a count of 58,654:

SELECT COUNT (DISTINCT [UniqueClaimID]) AS UniqueClaimID
  FROM [phm_db].[dbo].[PCP2Final]

The second query is:

SELECT COUNT (DISTINCT [UniqueClaimID]) AS UniqueClaimID, ProvOrgNm
FROM [phm_db].[dbo].[PCP2Final]
GROUP BY ProvOrgNm

When I run this query, the total count when I add the UniqueClaimID's for each of the ProOrgNm, I end up with 211,501. How is that possible? Any and all assistance would be greatly appreciated.

Sounds like UniqueClaimID can span multiple ProvOrgNam values, so it is being counted once for each ProvOrgNam