Delete dupes except for most recent

  • I have two tables

    tblDupeIDs (EnrollmentID int, MaxUploadDate DateTime)

    tblEnrollment (EnrollmentID int, UploadDate DateTime)

    I would like to delete all records from tblEnrollment where tblEnrollment.EnrollmentID = tblDupeIDs.EnrollmentID AND tblEnrollment.UploadDate <> tblDupeIDs.MaxUploadDate.

    Any thoughts on how to do this?

    Thanks!

    JM

  • try this

    DELETE tblEnrollment

    FROM tblEnrollment E

    JOIN tblDupeIDs D ON E.EnrollmentID = D.EnrollmentID

    AND E.UploadDate <> D.MaxUploadDate

  • You know I have written so many joins with = that I forgot that you can use <>.

    Thank you!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply