intermediate

EXCEPT Operator

5 min readLast updated: 2026-07-23

Overview

The EXCEPT operator (called MINUS in Oracle) returns distinct rows from the first query that do not exist in the second query.

Learning Objectives

  • Perform set subtraction using EXCEPT.
  • Identify records in Table A missing from Table B.

Detailed Concept Explanation

EXCEPT takes rows from Query A and subtracts any rows that match Query B:

  • Output = (Rows in A) - (Rows in B).
  • Duplicate rows in Query A are removed.

Code Examples

SQL

sql
-- Find products that have been registered but NEVER sold
SELECT product_id FROM products
EXCEPT
SELECT product_id FROM order_items;

Summary

EXCEPT returns distinct rows from the first query that are missing from the second query.