SQL INTERSECT and EXCEPT
Rows in both results / rows in the first only.
Syntax
SELECT … INTERSECT SELECT … SELECT … EXCEPT SELECT …
Example
Query (on the shop database used in the SQL course)
SELECT customer_id FROM customers EXCEPT SELECT customer_id FROM orders;
Result
| customer_id |
|---|
| 5 |
| 12 |
| 18 |
3 rows
Good to know. Oracle calls EXCEPT "MINUS".
Related
Learn it step by step in the free lesson Subqueries & Set Operations, with exercises that check your queries.