2011-06-02 40 views
2

在我的表中,ID是主键字段和标识列。 我想检查重复记录。 (当然重复的记录没有相同的ID)检查表中的重复记录Id是身份

并没有相同的日期字段。

我该如何检查。

附加信息:我有10列1 ID,2日期和其他3字符串,3 INT,1位。

Thansk在提前。

+0

编辑:重复将有“其他3串,3 Int,1位。 ”列相同。 – 2011-06-02 14:39:56

回答

4

您可以使用GROUP BY将类似的记录算来,然后添加一个HAVING子句过滤出出现不止一次的那些:

select StringCol1, StringCol2, StringCol3, IntCol1, IntCol2, IntCol3, BitCol1, count(*) as Count 
from MyTable 
group by StringCol1, StringCol2, StringCol3, IntCol1, IntCol2, IntCol3, BitCol1 
having count(*) > 1 
+1

谢谢。像魅力一样工作。 – 2011-06-02 14:51:46

1

请使用GROUP BY将类似的记录,并指定条件。

select count(string1), count(string2),count(string3),count(int1), count(int2),count(int3),count(bit1) 
from table1 
group by string1, string2, string3, int1, int2, int3, bit1 
having count(string1) > 1 and count(string2) > 1 and count(string3) > 1 and count(int1) > 1 and count(int2) > 1 and count(int3) > 1 and count(bit1) > 1 
0

通用方法如下。希望这可以帮助你。

SELECT COL1, COL2, ..., COLn, COUNT(*) 
FROM TABLE1 
GROUP BY COL1,COL2, .., COLn 
HAVING COUNT(*) > 1