INTERSECT returns rows that appear in BOTH query results; EXCEPT (MINUS in Oracle) returns rows of the first that never appear in the second. Both are set operations over entire result sets, and both remove duplicates by default — INTERSECT ALL / EXCEPT ALL keep them. They turn “which of these two lists overlap?” into a single query instead of a spreadsheet vlookup.
--how it works
1
Two results, one shape
Like UNION, both SELECTs must agree on column count and compatible types — the rule for every set operation.
2
INTERSECT keeps the overlap
Only rows present in BOTH results survive — and the output is distinct, even if a row appeared many times on each side.
3
EXCEPT keeps the difference
Rows of the first result with no match in the second survive; EXCEPT ALL would keep first-side duplicates.
4
Symmetry note
A EXCEPT B ≠ B EXCEPT A — order matters. INTERSECT is symmetric and associative; chain with parentheses when mixing.
5
Dedup is built in
Both operators remove duplicates unless you write INTERSECT ALL / EXCEPT ALL — unlike JOINs, which multiply.
--visualization
Oracle spells EXCEPT as MINUS
Stage 1 / 4
Query A (employees) → {Engineering, Sales, Marketing}. Query B (departments) → the same three. Both deduped first.
--example
query.sql
1SELECTdepartmentFROMemployees
2INTERSECT
3SELECTdept_idFROMdepartments;
Result
department
Engineering
Marketing
Sales
Both queries return the same three department names, so INTERSECT hands back all three. EXCEPT with the same inputs would return nothing — every employee department has a matching departments row.
--variants
INTERSECT — shared values
Which departments exist on both sides?
query.sql
1SELECTdepartmentFROMemployees
2INTERSECT
3SELECTdept_idFROMdepartments
4ORDERBY1;
Result
department
Engineering
Marketing
Sales
1Both sides resolve to the same three department names.
2All three are common to both results, so all three survive — deduplicated.
3Add a Research department with no employees and it disappears here — no employees reference it.
EXCEPT — first without second
Departments that have no employees (empty teams).
query.sql
1SELECTdept_idFROMdepartments
2EXCEPT
3SELECTdepartmentFROMemployees;
Result
dept_id
Research
1Imagine Research was added to departments but nobody transferred yet.
2It appears on the left, never on the right — so it survives EXCEPT.
3This “left anti-join” reading — A without B — is the operator’s everyday use.
EXCEPT is not symmetric
Swapping the sides changes the answer.
query.sql
1SELECTdepartmentFROMemployees
2EXCEPT
3SELECTdept_idFROMdepartments;
4-- vs
5SELECTdept_idFROMdepartments
6EXCEPT
7SELECTdepartmentFROMemployees;
Result
result
query 1 → (empty)
query 2 → Research
1Every employee department has a matching departments row, so query 1 finds nothing to keep.
2Reversed, departments minus employee-departments leaves Research.
3Read A EXCEPT B aloud as “A but not B” — direction is the semantics.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses →Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free →Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books →