Query rows with common value over result set partition
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