EXCEPT is a set operator defined in the SQL standard. It compares two result sets returned by independent SELECT statements and outputs only the unique rows that exist in the first set but not in the second. Duplicate rows are eliminated from both inputs before comparison, so the output is always distinct. Column counts and data types must match positionally across the two SELECT statements. Ordering is not preserved unless an outer ORDER BY clause is supplied. Some systems offer EXCEPT ALL to retain duplicates, but plain EXCEPT behaves like EXCEPT DISTINCT. When combining multiple set operators, parentheses clarify precedence. Performance depends on the underlying optimizer, but indexes and compatible data types improve speed. In Oracle, the equivalent operator is MINUS. MySQL lacks native EXCEPT support, requiring workarounds with LEFT JOIN or NOT EXISTS.
UNION, UNION ALL, INTERSECT, INTERSECT ALL, MINUS, NOT EXISTS, LEFT JOIN
SQL:1999
EXCEPT returns the distinct rows that are present in the first SELECT result set but absent in the second.
No. Plain EXCEPT removes duplicates. Use EXCEPT ALL (where supported) if you need to keep them.
Yes. Add an ORDER BY clause after the entire EXCEPT expression, not inside the individual SELECT statements.
Oracle uses the MINUS operator. MySQL has no equivalent, so use LEFT JOIN or NOT EXISTS patterns instead.