Keep shared rows with INTERSECT
INTERSECT returns distinct rows present in both inputs. It compares complete selected rows, not just the first column. A name repeated several times in both lists still appears once without ALL.
Data model
Example data
These tables are already loaded at the start of this lesson.
garden_club
One row represents one recorded club-membership name.
| Field / SQL type | Meaning | Rules |
|---|---|---|
name · text | Member name used as the invitation label, not a verified person identifier. | Nullable; NULL means no name value is recorded. |
No key or foreign key is declared. Names can repeat, and equal names need not identify the same real person. Set operations compare the selected name values rather than joining identities.
This table has no declared primary or unique key; distinct sample values are not a uniqueness guarantee.
repair_club
One row represents one recorded club-membership name.
| Field / SQL type | Meaning | Rules |
|---|---|---|
name · text | Member name used as the invitation label, not a verified person identifier. | Nullable; NULL means no name value is recorded. |
No key or foreign key is declared. Names can repeat, and equal names need not identify the same real person. Set operations compare the selected name values rather than joining identities.
This table has no declared primary or unique key; distinct sample values are not a uniqueness guarantee.
Only names shared by both clubs remain. Adding another copy of Bo to either input would not add another row to this distinct overlap.
SELECT name
FROM garden_club
INTERSECT
SELECT name
FROM repair_club
ORDER BY name;