Query rows with common value over result set partition I'm on Postgres 11 and I have these tables

 foo              foobar

| id |      | foo_id | bar_id |
------      -------------------
|  a |      |      a |      1 |
|  b |      |      a |      2 |
|  c |      |      b |      2 |
|  d |      |      b |      3 |


And I need all bar_id which are common to all foos. So I have this query:

select b.bar_id from foo f join foobar b on b.foo_id = f.id


which gives me

1
2
2
3


while I'd need just 2, i.e. the intersection of the result set partitioned by f.id. Then, I might apply a where clause, e.g. where f.id in (...). How can I achieve this?
It seems that your desired result do not use all foo values, there is no ('c',2) and ('d',2), then you can remove it from the equation and use only foobar table.

select
    barid
from
    foobar
group by 
    barid
having 
    count(fooid) = (select count(distinct fooid) from foobar);




| barid |
| ----: |
|     2 |



db&lt;>fiddle here