This is a discussion on Showing record rows in group by SQL within the SQL Server forums, part of the Microsoft SQL Server category; --> I know I should know this but here goes... I have a table with the following rows: UniqueID int ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I know I should know this but here goes... I have a table with the following rows: UniqueID int IDENTITY ParentUniqueID int RecordLabel nvarchar(50) RecordText ntext RecordDate DateTime What I'm trying to do is to group all records by ParentUniqueID and display the RecordLabel, RecordText and RecordDate from the most recent row for each grouped ParentUniqueID. In other words I need to GroupBy ParentUniqueID and show only the RecordLabel, RecordText and RecordDate for the MAX of RecordDate: Records in Table: UniqueID ParentUniqueID Recordlabel RecordText RecordDate 1 1 ThreadOne Blah-Abc 1/1/2005 2 1 ThreadOne Blah-Def 1/2/2005 3 3 ThreadTwo Blah-Ghi 1/2/3005 4 3 ThreadTwo Blah-Jkl 1/3/2005 5 1 ThreadOne Blah-Mno 1/4/2005 6 6 ThreadThree Blah-Pqr 1/5/2005 What I want to return: UniqueID ParentUniqueID Recordlabel RecordText RecordDate 4 3 ThreadTwo Blah-Jkl 1/3/2005 5 1 ThreadOne Blah-Mno 1/4/2005 6 6 ThreadThree Blah-Pqr 1/5/2005 The problem is I can't use a groupby clause with RecordLabel, RecordText, RecordDate because then it just returns all records (plus Recordtext is an ntext and I have to deal with that issue as well...) Any help is appreciated! lq |