其实可以用很简单SQL语句将其查询出来。如果想查询数据表中某一个字段重复(这里假设这个字段名是ID1),可以使用以下SQL语句。 select Table1.* from Table1 right join ( select ID1 From Table1 Group by ID1 having Count(ID1) > 1 ) T on Table1.id1 = T.id1 如果想查询数据表某两个字段重复,则可以使用如下语句查询。 select Table1.* from Table1 right join ( select ID1, ID2 From Table1 Group by ID1, ID2 having Count(ID1) > 1 and Count(ID2) > 1 ) T 注:上面代码中出现的ID1和ID2字段均不是数据表主键。
可以用分组函数统计,例如在表test中查询id字段重复的数据,查询结果中id是重复的数据值,count(*)是重复的次数。
create table test(id number,name varchar2(20));
insert into test values(1,'a');
insert into test values(1,'b');
insert into test values(1,'c');
insert into test values(2,'d');
insert into test values(2,'e');
commit;
SELECT ID,COUNT(*) FROM TEST GROUP BY ID;
使用in或者exists
但是相对来说,使用in的速度慢,可以尝试使用exist(如果数据多,会更明显的感觉到,数据极少,几乎没差别)
1。使用in
SELECT service, name, note
FROM table01
WHERE service NOT IN (SELECT service FROM table02)
2。使用exists
select service, name, note
from table01
where not exists (select service from table02)