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 columns which have more the 2 values in other column

I have a table which have 3 columns and we need to select data of those rows which have multiple entry in the table.

 Column1  Colum2    Colum3
 ---------------------------
 ARRG   | MEM      | 10.12
 ARRG   | MHH      | 0.245
 ARRG   | MHH      | 0.246
 ABC    | HQ       | 0.246
 CDE    | PRT      | 97.0
 TST    | TRY      | 97.0

Now I want to write a query to select rows from Column1 which have unique values in Colum2
Basically i want to print the rows of ARRG as this have 2 different values in Colum2.

ARRG   | MEM      | 10.12
ARRG   | MHH      | 0.245

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 :

Try:

select Column1,Colum2,Colum3
from test 
where Column1 in (select Column1
                  from test
                  group by Column1
                  having count(distinct Colum2)>1
                 )
group by Column1,Colum2,Colum3;

Demo

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