November 11, 2009 at 9:49 am
I have a scenario where there are 4 records with same ID. I need to write a code so that i can take only last 3 records.
Can anyone give me any idea what to do?
November 11, 2009 at 10:16 am
Look for ROW_NUMBER() in BOL (BooksOnLine, the help system usually installed together with SQL Server).
It requires an column for sorting. So you have to think what would be the definition for "last 3"... 😉
November 11, 2009 at 10:20 am
Modify the following:
;with numbered as(SELECT rowno=row_number() over
(partition by your duplicate column, order by Your duplicate column),col1, col2, col3 from your table name)
select * from numbered WHERE Rowno > 1
For more specific assistance please read the article whose link is in my signature block. This will help those who will try to help you, with a tested answer.
November 11, 2009 at 11:34 am
Thanks for the replies
I will try it out
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply