Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL to retrieve only duplicated values for a certain key

I have a table in Postgres as below :

Key    Value
1234   QAB009
1234   QAB009
1234   QAB010
1235   QAB011
1236   QAB012
1236   QAB012
1236   QAB013

I want output something similar to this , only values which are repeated more than once for a certain key

Key   Value
1234  QAB009
1236  QAB012

Appreciate any help!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use simple aggregation with a having filter:

select key, value
from t
group by key, value
having Count(*) > 1;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading