deleting dubilicate rows from tables

Discussion in 'Databases' started by seo-india, Aug 16, 2010.

  1. #1
    Dear user !

    we want to delete duplicate rows from tables in sql server 2005. please guide us how can do this work.
     
    seo-india, Aug 16, 2010 IP
  2. georgiivanov

    georgiivanov Member

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    25
    #2
    If your table does not have PRIMARY ID you have to use temp table:
    - CREATE temp_table
    - INSERT INTO temp_table SELECT DISTINCT * FROM table
    - TRUNCATE TABLE table
    - INSERT INTO table SELECT * FROM temp_table.

    If you have primary id for each row, the it is a little bit tricky. If you have another tables that point to the table, things might get messy :)
     
    georgiivanov, Aug 16, 2010 IP
  3. Carol Smith

    Carol Smith Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    DELETE FROM our_table
    WHERE rowid not in
    (SELECT MIN(rowid)
    FROM our_table
    GROUP BY column1, column2, column3... ;

    Here column1, column2, column3 constitute the identifying key for each record.
     
    Carol Smith, Aug 17, 2010 IP
  4. seo-india

    seo-india Banned

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    Thanks Mr. Carol Smith ! We are very grateful for your quick response .

     
    seo-india, Aug 18, 2010 IP