SELECT columns FROM table1
INTERSECT
SELECT columns FROM table2;SELECT columns FROM table1
EXCEPT
SELECT columns FROM table2;
Example
-- Customers who are also employeesSELECT email FROM customers
INTERSECT
SELECT email FROM employees;-- Customers who are NOT employeesSELECT email FROM customers
EXCEPT
SELECT email FROM employees;
Output
-- INTERSECT: emails in both tables
-- EXCEPT: emails only in customers
Note INTERSECT returns rows in both result sets. EXCEPT returns rows in the first set but not the second. MySQL 8.0.31+ supports these; earlier versions do not. SQL Server calls EXCEPT what PostgreSQL calls EXCEPT - they are the same. MINUS is Oracle's synonym for EXCEPT.
Frequently asked questions
How does JavaScript handle set difference?
This task is covered in 3 stacks on this page: JavaScript, Python, SQL. The "Set Methods (ES2025)" snippet in JavaScript uses `setA.union(setB)`.
Which code does the JavaScript example use?
The "Set Methods (ES2025)" snippet uses `setA.union(setB)`, from the Modern Features section of the JavaScript cheat sheet.
Which stacks cover "set difference" on this page?
JavaScript, Python, SQL. Together they hold 3 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Set Methods (ES2025)": ES2025. All methods return new Sets (non-mutating). Works with any iterable argument, not just Sets. Replaces manual loop-based set operations.