Every once in a while, I have a query that I just can't wrap my head around. I figure by posting here 1 of 2 things will happen. Somebody will come up with the query or I'll figure it out 30 seconds after I hit save.
I need to SELECT the latest record of type INIT for each user. Each user may have multiple INIT records, but only the latest one has any meaning. The table has a compound key consisting of Bldg, UserNo (yup, each building maintains its own records of employees) and a full time stamp. Thus:
Code:
Bldg ID TS Type OtherStuff
A 1 03-01-2001-07:30:25 INIT <more columns...> --1
A 2 02-01-2000-12:30:22 INIT <more columns...> --2
A 1 03-02-2001-11:12:52 ADJ <more columns...> --3
B 1 02-03-2002-15:00:12 INIT <more columns...> --4
A 1 04-17-2005-00:12:12 INIT <more columns...> --5
In this example, I need records 2, 4 and 5. Note, I need the entire record, including the <more columns...> stuff.
Can't seem to sort this one for some reason.