Given that (type_id, group_id) is the PK of widgets it is possible to avoid self-join:
select group_id from widgets
where type_id = A or type_id = B
group by group_id
having count(1) = 2;
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
