Re: Simpleish query I can't get my head around :)

From: Alan <alan_at_erols.com>
Date: Mon, 22 Nov 2004 10:43:23 -0500
Message-ID: <30eforF2uf0nuU1_at_uni-berlin.de>


"Robin Tucker" <idontwanttobespammedanymore_at_reallyidont.com> wrote in message news:cnsvgc$3gr$1$8300dec7_at_news.demon.co.uk...
> Hi,
>
>
> Can anyone tell me how to select the "most recent" date values from a
> grouped query? Consider the following:
>
> CREATE TABLE [dbo].[TestQuery] ( [ID] [int] NOT NULL , [ID_Parent] [int]
NOT
> NULL , [Date] [datetime] NOT NULL ) ON [PRIMARY]
>
> This is a simplified adjacency list. What I want to do is find the
highest
> valued item by date for each sub-tree. In other words, the single highest
> date item when This.ID_Parent = That.ID_Parent. I think I first need to
> group by ID_Parent, sort by Date (descending), then select the TOP 1 from
> this query,
> but how to aggregate them so I get the TOP 1 for each ID_Parent?
>
>
> Thanks for any help you can give me,
>
>
>
>
>
> Robin
>
>

Look up MAX() and GROUP BY Received on Mon Nov 22 2004 - 16:43:23 CET

Original text of this message