I have a table design like so
person_id | department
1 | a
1 | b
2 | a
2 | c
3 | b
3 | a
and would like to have a query return all of the person_id’s that belong to both department a and b. I figured it would be something along the lines of
select person_id from table group by person_id having ....
but can’t quite figure it out. Does anyone know how I can do this?
Edit: I figured out I can do the following. But it seems like a hack.
select person_id from table where department='A' or department='B'
group by person_id having count(1) > 1
Note: The DISTINCT is only needed if a person can be a member of the same department more than once.