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 2000 Forums
 SQL Server Development (2000)
 Deleting older records

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2003-11-04 : 22:03:25
CREATE TABLE MyTable (
MyID INT,
CreateDate DATETIME
)

What's the simplest DELETE of all rows saving only the most current CreateDate for each value if MyID?

Sam

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-11-04 : 22:24:28

DELETE FROM MyTable
FROM
MyTable
INNER JOIN MyTable M2 ON M2.MyID = MyTable.MyID and M2.CreateDate > MyTable.CreateDate




Damian
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2003-11-04 : 22:33:03
Thanks Merkin

Sam
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2003-11-04 : 22:56:37
I kind'a like this syntax:


DELETE A
FROM dbo.Feedback2 A
INNER JOIN dbo.Feedback2 B ON A.CourseID=B.CourseID AND A.UserID=B.UserID AND A.FormID=B.FormID AND A.CreateDate < B.CreateDate


Didn't know an alias would work on a delete till now.

Sam
Go to Top of Page
   

- Advertisement -