I'm joining 2 tables that have a one to many relationship. I have a field named ClaimNo that I join on. The criteria for selecting records is on 2 fields on the many side. I only want to get a count of the unique ClaimNo. However, because on the many table I return multiples of claim no the count is too high.
If I don't use an aggregate function and call SELECT DISTINCT, like below, I get the correct number of unique claimno because claimno is the only output field.
What I want though, is just a single record with the count. If I use Count(), like below, the DISTINCT is ignored and the query counts all of the records on the many side.
So what I do now call the first query from a second query and then perfrom the Count() to get a single record with the count.
The question is, can I create one query that will give me a count of unique claimno.
Thanks,
Greg
If I don't use an aggregate function and call SELECT DISTINCT, like below, I get the correct number of unique claimno because claimno is the only output field.
Code:
SELECT DISTINCT CLAIM_MASTERS.CLAIMNO
FROM CLAIM_MASTERS INNER JOIN CLAIM_DETAILS ON CLAIM_MASTERS.CLAIMNO = CLAIM_DETAILS.CLAIMNO
WHERE (((CLAIM_DETAILS.ALLOWED)>0) AND ((CLAIM_DETAILS.NET)>0));
What I want though, is just a single record with the count. If I use Count(), like below, the DISTINCT is ignored and the query counts all of the records on the many side.
Code:
SELECT DISTINCT Count(CLAIM_MASTERS.CLAIMNO) AS CLAIMCount
FROM CLAIM_MASTERS INNER JOIN CLAIM_DETAILS ON CLAIM_MASTERS.CLAIMNO = CLAIM_DETAILS.CLAIMNO
WHERE (((CLAIM_DETAILS.ALLOWED)>0) AND ((CLAIM_DETAILS.NET)>0));
So what I do now call the first query from a second query and then perfrom the Count() to get a single record with the count.
The question is, can I create one query that will give me a count of unique claimno.
Thanks,
Greg