View Full Version : Non-Duplicates (only one record instance) with criteria


guanacux
06-24-2009, 10:56 AM
Hello, I'm starting to use access, is been about 5 years or so, since I've used it. Somethings are coming back as I would like them to. Here is my current problem. I have the following table:

SSN,LASTNAME,FIRSTNAME,EXAMTYPE,EXAMDATE,RESULT

Students can take the same exam at different dates, and in my query I only want to display the latest result for one particular exam.

So right now I have not only the same students taking different exams (same SSNs) but also the same student taking the same exam when he/she fails at its 1st, 2nd, etc attempt (SAME SSNs, SAME EXAMTYPE).
In esence I want a query that only shows distinct values for SSN,LASTNAME,FIRSTNAME,EXAMTYPE,EXAMDATE,RESULT where I only show the latest result whether is a pass or fail, I don't care, but it has to be the latest of a given examtype.
so the table looks like this now:

xxx-xxx-1234,Doe,John,001,1/1/2008,F
xxx-xxx-1234,Doe,John,001,2/1/2008,P
xxx-xxx-4567,Doe,Jane,002,2/1/2008,P
xxx-xxx-4567,Doe,Jane,003,2/1/2008,F
xxx-xxx-4567,Doe,Jane,003,3/1/2008,F
xxx-xxx-1346,Jobs,Steve,004,3/1/2008,P
xxx-xxx-1234,Doe,John,004,5/1/2008,P

I want a query result like these:
xxx-xxx-1234,Doe,John,001,2/1/2008,P
xxx-xxx-4567,Doe,Jane,002,2/1/2008,P
xxx-xxx-4567,Doe,Jane,003,2/1/2008,F
xxx-xxx-1346,Jobs,Steve,004,3/1/2008,P
xxx-xxx-1234,Doe,John,004,5/1/2008,P

Thank you for all your replies

pbaldy
06-24-2009, 11:18 AM
Sounds like this type of thing:

http://www.baldyweb.com/LastValue.htm

except you'd be grouping/joining on both SSN and exam type.

guanacux
06-30-2009, 11:26 AM
Thank you so much, that solved my problem! Thank you so much!!!

For the record..the queries ended looking like these:

Query1:

SELECT Max(Table1.EXAMDATE) AS MaxOfEXAMDATE, Table1.SSN, Table1.EXAMTYPE FROM Table1 GROUP BY Table1.SSN, Table1.EXAMTYPE;

Query2:

SELECT Table1.* FROM Table1 INNER JOIN QueryTest ON (Table1.EXAMDATE = QueryTest.MaxOfEXAMDATE) AND (Table1.EXAMTYPE = QueryTest.EXAMTYPE) AND (Table1.SSN = QueryTest.SSN);

pbaldy
06-30-2009, 11:36 AM
No problem, and welcome to the site by the way!