View Single Post

   
  #1 (permalink)  
Old 02-29-2008, 07:12 AM
John A Fotheringham
 
Posts: n/a
Default How to get the last occurence of rows containing disticnt value in one column

I have a table that tracks GPS records broadly speaking as follows

ts DATETIME
username VARCHAR(16)
...
GPS data
...

I want to select the most recent GPS data for each distinct user.
That is, the table will have may records for a given username, but I
only want the most recent for each one.

For a single user I know I can do

SELECT TOP 1 * from <table> order by ts desc

But I want a set of results that effectively does this for
all users, and I can't work out the necessary query/subquery I
should be using.

I'm sure I'm missing something fairly obvious, so usual newbie
disclaimers apply.


--
HTML-to-text and markup removal with Detagger
http://www.jafsoft.com/detagger/
Reply With Quote