Access query, selecting only max record

I have a table with three columns (ID, ProductIDNo, DateReceived).
 ProductIDNo field has duplicates with different DateReceived values.
 I want to filter it to include all records only for Max DateReceived for that record.
 Is this possible?

I posted a similar, but opposite, question yesterday (thank you for the help, Rey)
Below selects all of the records that are less than the Max DateReceived :
SELECT T.*
 FROM CPEQUP T
 Left Join
 (SELECT CPEQUP.ProductIDNo, Max(CPEQUP.DateReceived) AS MaxOfDateReceived
 FROM CPEQUP
 GROUP BY CPEQUP.ProductIDNo) As T1
 ON T.DateReceived=T1.MaxOfDateReceived
 Where T1.MaxOfDateReceived Is Null
Mark DrelingerMISAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
try if this will give the result you want

SELECT CPEQUP.ProductIDNo, Max(CPEQUP.DateReceived) AS MaxOfDateReceived
 FROM CPEQUP
 GROUP BY CPEQUP.ProductIDNo
0
Mark DrelingerMISAuthor Commented:
Thank you, Rey.
If I want to include other columns that are in that table in the result (for example CustomerNo, Make), how could I include them ?
When I try to just add them to the select, I get an error that they are not part of the aggregate function?
0
Rey Obrero (Capricorn1)Commented:
try this

SELECT T.*
 FROM CPEQUP T
Inner Join
 (SELECT CPEQUP.ProductIDNo, Max(CPEQUP.DateReceived) AS MaxOfDateReceived
 FROM CPEQUP
 GROUP BY CPEQUP.ProductIDNo) As T1
 ON T.DateReceived=T1.MaxOfDateReceived And T.ProductIDNo=T1.ProductIDNo
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mark DrelingerMISAuthor Commented:
Is there any way to include the records where either ProductIDNo or the DateReceived is null. This version excludes the records where either of those fields are null.
0
Rey Obrero (Capricorn1)Commented:
how can you have a DateReceived data for null ProductID?


try this


SELECT T.*
FROM CPEQUP AS T INNER JOIN (SELECT CPEQUP.ProductIDNo, Max(CPEQUP.DateReceived) AS MaxOfDateReceived
  FROM CPEQUP
  GROUP BY CPEQUP.ProductIDNo)  AS T1 ON (T.ProductIDNo = T1.ProductIDNo) AND (T.DateReceived = T1.MaxOfDateReceived)

UNION ALL

SELECT CPEQUP.*
FROM CPEQUP
WHERE (CPEQUP.ProductIDNo) Is Null OR (CPEQUP.DateReceived) Is Null
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark DrelingerMISAuthor Commented:
very astute question :)
We've merged two systems, and the old system had customer inventory loaded that we didn't actually sell to the customer. So, there was no delivery date.  But the data still has value.
0
Mark DrelingerMISAuthor Commented:
Thanks for all the help.
Mark
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.