Computer Science · Ch 9 — Structured Query Language (SQL)
Intersect (∩)
Intersect (∩)
The INTERSECT operation in SQL is used to find common rows between two tables. It corresponds to the mathematical intersection of sets, represented by the symbol ∩. If you picture two overlapping circles, the intersection is the region that belongs to both circles — only the elements present in both sets survive. Figure 9.5 illustrates this: both circles are unfilled, and only the lens-shaped overlap is shaded.
In the context of databases, INTERSECT returns only those tuples (rows) that appear in both tables being compared. Any row that exists in only one of the two is excluded.
INTERSECT is a set operation in SQL, similar to UNION and MINUS. Duplicates are removed from the final result.
Example from the textbook
Using the DANCE and MUSIC relations introduced in Section 9.10.1 (Tables 9.18 and 9.19), suppose we want the list of students participating in both Dance and Music. Applying the INTERSECT operation on the two tables gives the result shown in Table 9.21:
| SNo | Name | Class |
|---|---|---|
| 2 | Mahira | 6A |
| 4 | Sanjay | 7A |
Only Mahira (class 6A) and Sanjay (class 7A) appear in both the Dance and Music participant lists — every other student is dropped.
Key points to remember
- INTERSECT is a set-based operation — it compares entire rows, not individual columns. …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your textbook's own diagram.
The same Music/Dance circles as Figure 9.4, but here only the overlapping middle region is shaded — the students who are in BOTH Music and Dance at the same time. …
| SNo | Name | Class |
|---|---|---|
| 2 | Mahira | 6A |