SQL EXCEPT
EXCEPT subtracts one compatible result set from another.
EXCEPT returns rows from the first query that don't appear in
the second query. It reads like subtraction: start with a full list, then
remove the rows found by another SELECT.
This can express missing-match questions clearly, especially when the final output is a simple list of values or identifiers.
select value_column
from full_list
except
select value_column
from values_to_remove The selected row is the comparison
EXCEPT compares every selected column. Keep both sides aligned
and avoid adding extra columns to only one side of the query.
Schema · Garden Shop Tables · orders, customers 2 tables
One row per order. Unshipped orders have a null shipped_date.
One row per customer. Some customers have no phone on file.
Return customer_id, first_name, and
last_name for active customers who have
never had a shipped order.
Run your query to inspect the result.
Expected answer
- Columns: customer_id, first_name, last_name.
- Rows: active customers with no shipped order rows.
- EXCEPT compares the full selected row, so both SELECT statements use the same columns.
That's the last lesson in “Set Operations.”
The next chapter builds on what this one covered.
Start Chapter 16: Summary Reports and Pivots → Begins with 16.1 Pivoting with conditional aggregationRelated
INNER, LEFT, RIGHT, FULL, and CROSS joins.
Join types and common join patterns.
Practice join keys, left joins, duplicate rows, and debugging.
One-to-many joins can inflate totals.
Qualify shared columns with a table alias.
Nested SELECTs, IN, EXISTS, and correlation.