2

I tried this with solutions avaialble online, but none worked for me.

Table :
Id rank 
1  100
1  100
2  75
2  45
3  50
3 50

I want Ids 1 and 3 returned, beacuse they have duplicates.

I tried something like

 select * from A where rank in ( 
 select rank from A group by rank having count(rank) > 1

This also returned ids without any duplicates. Please help.

3

3 Answers 3

4

Try this:

select id from table
group by id, rank
having count(*) > 1
Sign up to request clarification or add additional context in comments.

4 Comments

This gives me Id with more than one value. I am trying to get the ones with duplicates. Thanks
Yeap sorry, correected it. I missed the rank
Thank you. :) I dont know what I would do without these forums and you guys. Learning each time..:)
Welcome ^.^ Anyway, this is not a forum -- The main difference is that all the interaction here is asking a question, answering the question, voting it and accepting answers. Nothing else :)
1
select id, rank
from
(
    select id, rank, count(*) cnt
    from rank_tab
    group by id, rank
    having count(*) > 1
) t

Comments

1

This general idea should work:

SELECT id
FROM your_table
GROUP BY id
HAVING COUNT(*) > 1 AND COUNT(DISTINCT rank) = 1

In plain English: get every id that exists in multiple rows, but all these rows have the same value in rank.


If you want ids that have some duplicated ranks (but not necessarily all), something like this should work:

SELECT id
FROM your_table
GROUP BY id
HAVING COUNT(*) > COUNT(DISTINCT rank)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.