Databases Reference
In-Depth Information
(3,4) (from member 3)
If it were not for the clause
Equality.Set
<
E2.Set
, we would also be getting (1,1),
(2,2), ... (4,4), as well as (2,1), (3,1), and so on.
Now we ask the question, “How many times will a given set pair appear?” A given set
pair, say (1,2), will appear as many times as there are common elements between the two
sets. That is, it will appear as many times as the size of the intersection of the two sets.
So if we
GROUP
BY
set pair, we can examine these intersections and restrict the returns
using a
HAVING
clause. The
HAVING
clause we want says that the two sets are equal. But
two sets A and B are equal if the sizes of A, B, and the intersection of A and B are all the
same! The clause:
(SELECT Count(Member) FROM Equality As E3 WHERE E3.Set=Equality.Set) =
(SELECT Count(Member) FROM Equality As E3 WHERE E3.Set=E2.Set)
says that, for a given set pair (
Equality.Set
,
E2.Set
) from the main
SELECT
clause, the
size of
Equality.Set
is equal to the size of
E2.Set
. The clause:
Count(Equality.Set) =
(SELECT Count(Member) FROM Equality As E3 WHERE E3.Set=E2.Set)
says that the size of the intersection of
Equality.Set
and
E2.Set
is the same as the size
of
E2.Set
. That's it.