Hi,
I have a table with room, sequence number, and date. A room can have multiple records, with seqno increasing sequentially within each room number.
(ex: room 100, seq 1 date 7/01/2006
room 100, seq 2 date 7/05/2006
room 100, seq 3 date 7/11/2006
room 101, seq 1 date 7/02/2006...)
I want to display each room with its highest sequence number, AND the date. I wrote a query that displays the room and seqno only, but don't know how to display the date, which is not part of the Max or Group By (aggregate) portions and I get errors when I try.
What I REALLY want to do, ultimately, is then take the date and update a date field on a second table for this room number. I've just been doing it in baby steps.
My current SQL is:
Would greatly appreciate any help. I think once I get the aggregate query part working, I can figure out the update (altho' I shouldn't be so sure!).
Thanks in advance.
I have a table with room, sequence number, and date. A room can have multiple records, with seqno increasing sequentially within each room number.
(ex: room 100, seq 1 date 7/01/2006
room 100, seq 2 date 7/05/2006
room 100, seq 3 date 7/11/2006
room 101, seq 1 date 7/02/2006...)
I want to display each room with its highest sequence number, AND the date. I wrote a query that displays the room and seqno only, but don't know how to display the date, which is not part of the Max or Group By (aggregate) portions and I get errors when I try.
What I REALLY want to do, ultimately, is then take the date and update a date field on a second table for this room number. I've just been doing it in baby steps.
My current SQL is:
Code:
SELECT tblPestTreatmentDetails.RoomID, Max(tblPestTreatmentDetails.TreatmentSeqNum) AS MaxOfTreatmentSeqNum, tblPestTreatmentDetails.TreatmentDate
FROM tblPestTreatmentDetails
GROUP BY tblPestTreatmentDetails.RoomID
ORDER BY tblPestTreatmentDetails.RoomID;
Would greatly appreciate any help. I think once I get the aggregate query part working, I can figure out the update (altho' I shouldn't be so sure!).
Thanks in advance.