duplicates in query

G

gregatvrm

I am trying to find how many people of a certain sex returned in the same
year and it keeps giving me both records of the same person. How do i get it
to return only the one record. Also if there is a null response it needs to
return a zero.

SELECT Count(History.RESID) AS NumberOfDups
FROM RESIDENT INNER JOIN History ON RESIDENT.RESID = History.RESID
WHERE (((History.ExitDate) Between #1/1/2007# And #12/31/2007#) AND
((RESIDENT.Sex)="f")) OR (((History.ExitDate) Is Null))
GROUP BY RESIDENT.LastName, RESIDENT.FirstName, History.RESID
HAVING (((Count(History.RESID))>1));
 
K

KARL DEWEY

Maybe this is what you want.
SELECT Sum(IIf(([History].[RESID]) Is Null,0,1)) AS NumberOfDups,
RESIDENT.LastName, RESIDENT.FirstName
FROM RESIDENT LEFT JOIN History ON RESIDENT.RESID = History.RESID
WHERE (((History.ExitDate) Between #1/1/2007# And #12/31/2007#) AND
((RESIDENT.Sex)="f")) OR (((History.ExitDate) Is Null))
GROUP BY RESIDENT.LastName, RESIDENT.FirstName, History.RESID
HAVING (((Sum(IIf(([History].[RESID]) Is Null,0,1)))<>1));
 
G

gregatvrm

Sorry for the late response. This works great. Your Awesome!

KARL DEWEY said:
Maybe this is what you want.
SELECT Sum(IIf(([History].[RESID]) Is Null,0,1)) AS NumberOfDups,
RESIDENT.LastName, RESIDENT.FirstName
FROM RESIDENT LEFT JOIN History ON RESIDENT.RESID = History.RESID
WHERE (((History.ExitDate) Between #1/1/2007# And #12/31/2007#) AND
((RESIDENT.Sex)="f")) OR (((History.ExitDate) Is Null))
GROUP BY RESIDENT.LastName, RESIDENT.FirstName, History.RESID
HAVING (((Sum(IIf(([History].[RESID]) Is Null,0,1)))<>1));


gregatvrm said:
I am trying to find how many people of a certain sex returned in the same
year and it keeps giving me both records of the same person. How do i get it
to return only the one record. Also if there is a null response it needs to
return a zero.

SELECT Count(History.RESID) AS NumberOfDups
FROM RESIDENT INNER JOIN History ON RESIDENT.RESID = History.RESID
WHERE (((History.ExitDate) Between #1/1/2007# And #12/31/2007#) AND
((RESIDENT.Sex)="f")) OR (((History.ExitDate) Is Null))
GROUP BY RESIDENT.LastName, RESIDENT.FirstName, History.RESID
HAVING (((Count(History.RESID))>1));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top