View Single Post

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

"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote:

>What is the primary key? I'll assume the key consists of (ts,
>username), in which case the folllowing should do what you want:
>
>SELECT ts, username, ... /* other columns */
> FROM YourTable AS T
> WHERE ts =
> (SELECT MAX(ts)
> FROM YourTable
> WHERE username = T.username)


Thanks

>It really helps if you include DDL with questions like this (basically
>a CREATE TABLE statement, including keys and constraints). The exact
>table structure may make a big difference to the possible solutions.


Point noted.

>The usual recommendation that you shouldn't use SELECT * in production
>code also applies.


I realise this. That was just me being lazy (although for some of my
selects I do want the entire row).

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