delete duplicates

Results 1 to 2 of 2

Thread: delete duplicates

  1. #1
    Join Date
    Dec 1969

    Default delete duplicates

    can someone help me. i need to delete records with duplicate ClassNames in a table. just not able to get it rigt. please do help. <BR><BR>tblClass<BR><BR>ClassId (PK) Int<BR>ClassName Varchar(15)<BR>ClassDesc Varchar(100)<BR><BR>thanks in advance <BR>milind

  2. #2
    Join Date
    Dec 1969

    Default RE: delete duplicates

    DELETE FROM tblClass <BR>WHERE ClassID IN (<BR> SELECT MAX(ClassID) FROM tblClass<BR> GROUP BY ClassName<BR> HAVING COUNT(ClassName) &#062; 1)<BR><BR>This gets all the records which have duplicate ClassNames, and deletes those records with the largest ID<BR><BR>Be sure to test it first with a SELECT instead of a delete!! <BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts