database - SQL selection based on two variables, exclusive of others -


i'm querying table looking @ 3 fields; unit_id, group_id, , service.

each unit_id unique, , has single group_id , service associated it.

i want return group_id , service units group_id have same service. instance, if have:

unit_id    group_id    service 1          group_a     apple 2          group_b     orange 3          group_b     apple 4          group_a     apple 5          group_c     banana 

i want return group_a , group_c, because services in group_ids same, whereas group_b has both orange , apple.

how write sql query accomplishes that?

thanks much.

select * your_table group_id in (   select group_id   your_table   group group_id   having count(distinct service) = 1 ) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -