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

Oracle SQL select from multiple condition but with has same id's

I will retrieve data fom oracle database. It has table as you see in picture below. (Table Name is ATTRIBUTE_TAB)

I want to query:

if (VALUE_NO=’6000′ VALUE_TEXT=’TEMPERED’ VALUE_TEXT=BLUE) but these rows has to be same id.

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

I explained in picture below.

My Query is

SELECT * FROM ATTRIBUTE_TAB
WHERE VALUE_NO='6000' OR VALUE_TEXT='TEMPERED'OR VALUE_TEXT='BLUE

but I couldn’t integrate the id status into the code.

enter image description here

>Solution :

You can use aggregation as the following:

SELECT * FROM ATTRIBUTE_TAB
  WHERE ID IN
  (
    SELECT ID FROM ATTRIBUTE_TAB
    WHERE VALUE_NO='6000' OR VALUE_TEXT='TEMPERED'OR VALUE_TEXT='BLUE'
    GROUP BY ID
    HAVING COUNT(*) = 3 -- or maybe HAVING COUNT(DISTINCT ATTRIBUTE) = 3 if duplicates are possible 
  )
ORDER BY ID, ATTRIBUTE DESC

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