Interview - Detect/remove duplicate entries

后端 未结 3 578
感情败类
感情败类 2020-12-11 13:29

how to detect/remove duplicate entries from a database in a table where there is no primary key ?

[If we use \'DISTINCT\' how do we know which record is the correct

3条回答
  •  再見小時候
    2020-12-11 14:10

    delete f
    from
    (
        select ROW_NUMBER() 
            over (partition by 
                YourFirstPossibleDuplicateField,
                YourSecondPossibleDuplicateField
                order by WhateverFieldYouWantSortedBy) as DelId
        from YourTable
    ) as f
    where DelId > 1
    

提交回复
热议问题