query to find most recent record

I have a table tracking serial numbered parts by location.  There are many records per serial number.  I need my report to only show the most recent entry for a serial number.  Currently, when the report opens the user is prompted for the serial number.  Then all the records for that serial number are displayed.  I just need the most recent.

Thanks,
Brooks
gbnortonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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:
select serialnumber, max([datefield])
from tableX
group by serialnumber
0
hieloCommented:
>> I just need the most recent.
Is there a field that reflects when it was added - ex: lastUpdate?
Yes:
SELECT TOP 1 [location] FROM Table WHERE [serialNumber]='XXX' ORDER BY [lastUpdate] DESC


Or an auto-number field - ex: ID?
SELECT TOP 1 [location] FROM Table WHERE [serialNumber]='XXX' ORDER BY [ID] DESC
0
gbnortonAuthor Commented:
capricorn1,
Here is my SQL statement with an attempt at your recommendation;
SELECT [Current Location].SerialNumber, max([Current Location].[Date Moved]), TubeData.Date_Received, TubeData.Customer, TubeData.TubeType, TubeData.SalesOrder, TubeData.CustomerPO, TubeData.VmiPartNumber, TubeData.Status, [Current Location].Area, [Current Location].[Date Moved]
FROM TubeData INNER JOIN [Current Location] ON TubeData.SerialNumber=[Current Location].SerialNumber
WHERE ((([Current Location].SerialNumber)=[Find Serial Number:]));

It generates the error "You tried to execute a query that does not include the speicified expression 'SerialNumber" as part of an agregate expression
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

hieloCommented:
try:
SELECT TOP 1 [Current Location].SerialNumber, [Current Location].[Date Moved], TubeData.Date_Received, TubeData.Customer, TubeData.TubeType, TubeData.SalesOrder, TubeData.CustomerPO, TubeData.VmiPartNumber, TubeData.Status, [Current Location].Area, [Current Location].[Date Moved]
FROM TubeData INNER JOIN [Current Location] ON TubeData.SerialNumber=[Current Location].SerialNumber
WHERE ((([Current Location].SerialNumber)=[Find Serial Number:]))
ORDER BY [Current Location].[Date Moved] DESC

Open in new window

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
gbnortonAuthor Commented:
helio,
How do I modify my SQL statement with your code?
SELECT [Current Location].SerialNumber, TubeData.Date_Received, TubeData.Customer, TubeData.TubeType, TubeData.SalesOrder, TubeData.CustomerPO, TubeData.VmiPartNumber, TubeData.Status, [Current Location].Area, [Current Location].[Date Moved]
FROM TubeData INNER JOIN [Current Location] ON TubeData.SerialNumber=[Current Location].SerialNumber
WHERE ((([Current Location].SerialNumber)=[Find Serial Number:]));

Thanks,
Brooks
0
gbnortonAuthor Commented:
Perfect!  Thank you.
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.