Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 picking record with latest date

Author  Topic 

itsarnie
Starting Member

18 Posts

Posted - 2010-05-11 : 06:27:09
Hi,

If I have duplicate records,I want to take the record with latest date.Please tell me how can I do this with SQL.

Regards,
Arnie.

Thanks and regards
Arnie,

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-05-11 : 07:00:42
;WITH CTE AS
(
SELECT ROW_NUMBER() OVER( PARTITION BY <column list> ORDER BY <date column> ) RowNo, * FROM <Your Table>
)
SELECT * FROM CTE WHERE RowNo = 1


Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-11 : 09:03:41
quote:
Originally posted by vaibhavktiwari83

;WITH CTE AS
(
SELECT ROW_NUMBER() OVER( PARTITION BY <column list> ORDER BY <date column> DESC) RowNo, * FROM <Your Table>
)
SELECT * FROM CTE WHERE RowNo = 1


Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-05-11 : 09:27:43
Madhi, Thanks for correction...

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-11 : 10:58:50
quote:
Originally posted by vaibhavktiwari83

Madhi, Thanks for correction...

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -