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

select distinct one column and pick just one occurence out of the second one

I have the below data:

id1 id2 other
1 a p
1 b q
2 c q
2 d q
2 e q

I want to select distinct id1. For id2, I just want the first occurrence – I don’t care about the rest like this:

id1 id2
1 a
2 c

Thanks!

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 :

Should be fairly simple:

select id1, min(id2) as id2
from that_table
group by id1
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