Intersection
Intersection of two sets A and B is the set containing all elements of A that also belong to B (or vice versa). In other words, it’s a set of common elements.
A \cap B = \{ x : x \in A \textrm{ and } x \in B \}
This reads as: Intersection of A and B is the set of elements x, where x belongs to A and x belongs to B.
For example, if A = \{1, 2, 3\}, and B = \{3, 4, 5\}, then 3 is the only element present in both sets:
A \cap B = \{3\}
Sidenote: I quickly remembered which symbol — \cup and \cap — means which operation by noticing that \cup looks like letter U, so it means union. I’ve had a similar moment when learning Boolean algebra and logic, where \wedge means AND and looks like A without the horizontal bar.
SQL has INTERSECT
:
SELECT username FROM customers
INTERSECT
SELECT username FROM managers;
Naturally, duplicates aren’t an issue for intersection, because by definition one pair of elements results in one element, and not two. If there are two elements in one set, and one same element in the other set, the result is still one common element in the intersection.
A Venn diagram for intersection is often used to show commonality. For example, coming back to sets of favorite movies, we can compare your favorite movies and mine and see if there are any movies we both love. If no such movies exist, then our sets are disjoint. Formally, two sets are disjoint if their intersection is an empty set:
A \cap B = \varnothing
A mathematician in love may describe the perfectness of their partner by saying that the partner’s qualities and bad qualities are disjoint sets. The partner would definitely accept this as a complement (sic)…