Unix Technical Forum

Showing record rows in group by SQL

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 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 06:45 AM
laurenq uantrell
 
Posts: n/a
Default Showing record rows in group by SQL

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:57 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com