This returns all the dispatch id's for each piece of equipment. I only want the most current record for each piece of equipment.
Main Topics
Browse All TopicsI have a table which i want to query for the most current records. The fields I want to use are:
Dispatch ID
Equipment #
Equipment Description
Job #
Job Name
Arrival Date
They are all in the same table and a new dispatch id is automatically issued everytime i change the location of a piece of equipment. I only want to return the results of where the equipment is now. Either by max Dispatch ID or max Arrival date. I am having no luck accomplishing this.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
that should ony return 1 record, matching the row with the the maximum dispatch id from the table
if you want to return the max dispatchid for each equipment # then you should do -
(btw do not put spaces or special characters in your field names it makes changing databases a real mess, and typing queries slower)
select yt.* from yourTableName as yt,
(seelct equipmentNo, max(Dispatch_ID) as md from yourTableName) as q
where yt.equipmentNo = q.equipmentNo and yt.Dispatch_ID = q.md
Business Accounts
Answer for Membership
by: Raynard7Posted on 2007-08-20 at 16:30:34ID: 19734543
there are a few ways of doing this, but I would just do
select top 1
[Dispatch ID],
[Equipment #],
[Equipment Description],
[Job #],
[Job Name],
[Arrival Date]
from
yourTableName
order by [Dispatch ID] desc