Search code examples
sqlsql-serversql-server-2000

How to delete the Duplicate rows


Table1

ID Date

001 23/02/2009
001 24/02/2009
001 24/02/2009
002 25/02/2009
002 25/02/2009
...

I want to delete the duplicate rows from the above table.

Expected Output

ID Date

001 23/02/2009
001 24/02/2009
002 25/02/2009
...

Need Query Help


Solution

  • Can't remember where I got it, but I used to use this SQL to remove duplicates from a table:

    begin tran deduplicate
    
    select DISTINCT *
    into #temp
    from mytable
    
    truncate table mytable
    
    insert mytable
    select *
    from #temp
    
    select * from mytable
    
    drop table #temp
    commit tran deduplicate