Reputation: 99
Table name is SAMPLE and Columns are DID, RID and CAT
In the table we see DID column 100 has same CAT values like CA repeated twice and the DID 200 and 500 also have duplicate values in CAT column. so i want in the output like below
100 CA
200 CA
500 OA
300 and 400 DID do not have any duplicate values are all unique so in my query these records should be excluded
Please help on the query part.
table information:
Upvotes: 1
Views: 518
Reputation: 35920
You can use group by
and having
as follows:
select did, cat
from your_table
group by did, cat
having count(1) > 1
You can also use the count
window function as follows:
select did, cat from
(select t.*, count(1) over (partition by did, cat) as cnt
from your_table t) t
where cnt > 1
Upvotes: 0