MS Access / SQL help please?
April 21, 2009 7:03 AM
Subscribe
I have a (hopefully easy) SQL question. I'm working in MS Access. Simplifying things a bit, I have a table with a TaskID, and a TaskStatusID. I want to get a list of each TaskID, and the newest TaskStatusID for each. (Details follow.)
The idea is a single task can have multiple statuses. My data looks like this:
TaskID = 1, TaskStatusID = 1
TaskID = 1, TaskStatusID = 2
TaskID = 1, TaskStatusID = 3
TaskID = 2, TaskStatusID = 4
TaskID = 2, TaskStatusID = 5
TaskID = 3, TaskStatusID = 6
TaskID = 4, TaskStatusID = 7
I want to get a list of each TaskID, and the newest TaskStatusID for each. So, I want a query that will return this:
TaskID = 1, TaskStatusID = 3
TaskID = 2, TaskStatusID = 5
TaskID = 3, TaskStatusID = 6
TaskID = 4, TaskStatusID = 7
The goal is to show that on a Continuous Form. I don't think this should be that difficult, but I'm learning as I go and just can't wrap my head around what the query should be. Any suggestions please? Thanks!
posted by inigo2 to computers & internet (7 comments total)
3 users marked this as a favorite
SELECT TaskID, MAX(TaskStatusID) FROM [TableName] GROUP BY TaskID
This is assuming that a higher TaskStatusID is newer.
posted by Horselover Fat at 7:16 AM on April 21