SQL DB2 - Select query based on a column value unique to another column -


i have table following fields:

id    |   attribute_id 200          3 200          4 200          6 200          7 201          6 202          2 202          6 203          6 204          2 204          4 204          6 

i want result this:

id    |   attribute_id 201          6 203          6 

basically, need write query has 'id' associated 'attribute_id' = 6 , not 'attribute_id' = 1,2,3. column value unique column value, if makes sense.

i using db2.

below attempt, sure doing wrong way.

select qa.id, qa.attribute_id     question_attributes qa     where(             (qa.id,qa.attribute_id) in (values (qa.id,4),(qa.id,6),(qa.id,7))         , (qa.id,qa.attribute_id) not in (values (qa.id,1),(qa.id,2),(qa.id,3))                     ) 

thanks suggestions.

you can approach aggregation , having clause:

select qa.id question_attributes group qa.id having min(attribute_id) = 6 , max(attribute_id) = 6; 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -