Suppose there are 2 tables as shown below. Table A contains rows in a few groups - 11 (1,2,3) and 22 (4,5,6,7) in this case. Table B contains book rows that indirectly reference groups in table A via B.a_id = A.a_id foreign key relationship):
Table A:
a_id  grp
---------
1     11
2     11
3     11
4     22
5     22
6     22
7     22
Table B:
b_id a_id book
--------------
1    1    AA
2    2    AA
3    3    AA
4    1    BB
5    2    BB
6    3    BB
7    1    CC
8    3    CC
9    4    AA
10   5    AA
11   6    AA
12   4    BB
13   5    BB
14   6    BB
15   7    BB
16   6    CC
17   7    CC
I need to select only those book/group combinations that are complete, i.e.
a_id  grp  book
---------------
1     11   AA
2     11   AA
3     11   AA
1     11   BB
2     11   BB
3     11   BB
4     22   BB
5     22   BB
6     22   BB
7     22   BB
11 CC, 22 AA or 22 CC are not eligible, as they do not represent complete groups. One way to get the desired result is to use row counts by each group in a subquery, but its seems kind of shaky. Any other ideas?
Thanks!
Edit: I don't think that the referenced question is really the same problem.
 
    