| Raman Iyer [MS] 2006-03-05, 8:24 pm |
| [forwarding to the relational database newsgroup]
"mccorb" < bmccormick@thalesnav
igation.com> wrote in message
news:u7CbFsvPGHA.3432@TK2MSFTNGP14.phx.gbl...
> First let me say that I am not an SQL expert but can usually navigate some
> pretty complex queries if I fight it long enough.
>
> However, this one has me baffled. I am sure I am overlooking somehting
> simple but not sure what that is. It only involves a single table.
>
> I have a table in the database I am working with with the following
> columns: (I have simplified this down for the sake of clarity)
> int p1
> int p2
> int p3
> int s1
> date d1
> string s1
>
> There is no primary key and the table more resembles a log than anything.
> e.g.
>
> p1 p2 p3 s1 d1 s1
> 1 12 14 100 23May comment 2
> 1 12 14 800 22May comment 1
> 1 12 14 300 24May comment 3
> 1 12 15 100 22May comment 2
> 1 12 15 800 21May comment 1
> 2 12 15 100 23May comment 1
>
> What I want to do is exttract the rows from the table where the
> combination of p1 p2 and p3 is distinct/unique and the date is the most
> recent one for all combinations of p1, p2, p3. So from the table above I
> would end up with the resultset:
>
> p1 p2 p3 s1 d1 s1
> 1 12 14 300 24May comment 3
> 1 12 15 100 22May comment 2
> 2 12 15 100 23May comment 1
>
>
> Any help would be greatly appreciated.
>
>
>
>
|