Intersection (∩) is a set‑oriented relational‑algebra operation that returns tuples present in both of two given relations. It behaves exactly like the mathematical intersection of two sets. In simple terms, the intersection operation gives you only those rows that exist in both tables, nothing more and nothing less.
Intersection is very useful when you want to find common records between two similar datasets, such as employees who work in two departments, customers who appear in both lists, or items that are present in two different time periods.
When Is Intersection Allowed? (Union Compatibility)
Like union, intersection requires that the two relations are union‑compatible:
They must have the same number of attributes.
The attributes must be in the same order.
Corresponding attributes must have compatible domains (same or compatible data types).
If the two relations are not union‑compatible, the intersection operation is not defined and cannot be applied.
Syntax of Intersection
The general syntax is:
and : the two input relations (tables).
The result is a new relation with the same schema as and , and only the tuples that appear in both and .
Because relations are treated as sets, each tuple appears at most once in the result.
Example of Intersection
Consider two tables storing temporary employee data with the same structure:
TEMP_A(emp_id, name, salary)
TEMP_B(emp_id, name, salary)
TEMP_A contains:
TEMP_B contains:
The intersection:
Gives a result like:
Only the rows that appear in both tables are kept; rows unique to either table are discarded.
Key Properties of Intersection
Intersection is commutative:
Intersection is idempotent:
because the common part of a set with itself is the set itself.
Intersection only works on union‑compatible relations; otherwise the operation is invalid.
Why Intersection Matters in DBMS?
It is useful for answering “which records are in both groups?” type questions, such as employees present in both departments, customers in both months, or products in both stores.
It corresponds to SQL‑like set‑oriented queries that use INTERSECT (where supported) or can be simulated using joins and conditions.
It reinforces the idea that relations are sets, so operations like union and intersection apply naturally in relational algebra.