[thelist] SQL - Getting most recent record of a combo
Bart
bam at mailandnews.com
Thu Jan 30 21:24:01 CST 2003
I have a SQL table that has two date fields and a one username field. One of
the fields is the event date ('event_date') and the other is essentially a
datetime stamp ('date_modified') of when the record was entered. There can be
multiple records for each event_date / username. I want to return only the
most recent record for each event_date / username combo. Here's what I have
so far:
select distinct event_date,username from mytable
Then I would programmatically loop thru all of those to get the most recent
record:
select top 1 * from mytable where username = " & rs("username") & " and
event_date = " & rs("event_date") & " order by date_modified desc
Is there a way to do this in a single query? I'm thinking I need to do a
GROUP BY but I'm a little fuzzy on how to structure it.
More information about the thelist
mailing list