Oracle 如何查询相同的数据

一个表中,请注意是一张表中。有两条重复的,也有三条重复的,我怎么查询出相同的数据来,过滤掉单条的数据。比如

id name age
001 a 18
002 b 19
001 a 18
003 c 20

我只查出001的两条。而过滤掉002.003.SQL该怎么写

如果你只要id重复的,是
select * from 表 where id in (select id from 表 group by id having count(*)>1)

如果你要所有字段都完全一样的重复记录的话,就是
select * from 表 where id in (select id from 表 group by id,name,age having count(*)>1)
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-28
1)
select *
from tab t
where exists (select 1 from tab where id = t.id and (name <> t.name or age <> t.age)

2)
select *
from tab
where id in (select id from tab group by id having count(*) > 1)本回答被提问者和网友采纳
第2个回答  2012-08-04
首先你说的重复是说id重复还是所有字段重复?select * from tablename group by id having count(*)>1。把id字段换成你认为是重复字段即可,如果是所有字段,则把所有字段写上去。
第3个回答  2012-08-04
像你给数的例子这样就可以了。
select distinct id,name,age from 表名 ;