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

From: Robin Tucker <idontwanttobespammedanymore_at_reallyidont.com>
Date: Mon, 22 Nov 2004 15:10:04 -0000
Message-ID: <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 Received on Mon Nov 22 2004 - 16:10:04 CET

Original text of this message