2008-11-20 23 views

回答

47

向人展示什麼樣的例子已經說明:

SELECT 
    Col1, -- All of the columns you want to dedupe on 
    Col2, -- which is not neccesarily all of the columns 
    Col3, -- in the table 
    Col4, 
    Col5, 
    Col6, 
    Col7, 
    Col8, 
    Col9, 
    Col10 
FROM 
    MyTable 
GROUP BY 
    Col1, 
    Col2, 
    Col3, 
    Col4, 
    Col5, 
    Col6, 
    Col7, 
    Col8, 
    Col9, 
    Col10 
HAVING 
    COUNT(*) > 1 
+0

釘住它的傢伙..謝謝你.. – Bajji 2008-11-24 12:17:08

12

您可以對所有列使用「分組依據」,然後COUNT(*)> 1

+2

這個效果很好,只記得排除一個合成PK,如果你有一個 – 2008-11-20 20:37:19

2

要由作爲古格上述檢出,只是組。

select fieldA, fieldB, count(*) from table 
group by fieldA, fieldB 
having count(*) > 1 

如果你想刪除愚弄......僞....

select distinct into a temp table 
truncate original table 
select temp table back into original table 

隨着截斷,如果你有FK的約束,你可能會遇到問題,所以聰明地取消約束,並確保你不會孤兒記錄。

6

試試這個

Select * From Table 
Group By [List all fields in the Table here] 
Having Count(*) > 1 
3

除了提供的建議,然後,我會去在防止重複的努力未來,而不是試圖在以後找到它們。

這是通過對列(或列組)應用唯一索引來完成的。請記住,數據庫中的數據可以從其他位置進行修改,而不是通過您正在使用的特定應用程序進行修改,因此最好在數據庫級別定義表中允許和不允許的內容。