Home » Topic » How to remove duplicate rows?

How to remove duplicate rows?

Lincoln Burrows ~ Modified: November 17th, 2015 ~ ~ 1 Minute Reading

Home Forums How to remove duplicate rows?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #888 Score: 0
    Lincoln Burrows
    Moderator
    16 pts

    I need to delete the duplicate rows in a table, any idea how to do this in SQL server?

    #890 Score: 0
    Andrew Jackson
    Moderator
    1 pt

    This will delete duplicate rows

    DELETE LU 
    FROM   (SELECT *, 
                   Row_number() 
                     OVER ( 
                       partition BY col1, col1, col3 
                       ORDER BY rowid DESC) [Row] 
            FROM   mytable) LU 
    WHERE  [row] > 1 
    
    #905 Score: 0
    Stephen West
    Moderator
    4 pts

    1. SELECT the DISTINCT records into a New Table
    2. TRUNCATE the Old Table
    3. MERGE the New Table back into the Old Table

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.