The SQL EXCEPT operator takes the distinct rows of one query and returns the rows that do not appear in a second result set. For purposes of row elimination and duplicate removal, the EXCEPT operator does not distinguish between
NULLs. The EXCEPT ALL operator does not remove duplicates, but if a row appears X times in the first query and Y times in the second, it will appear \max(X - Y, 0) times in the result set. Notably, the Oracle platform provides a MINUS operator which is functionally equivalent to the
SQL standard EXCEPT DISTINCT operator.
Example The following example EXCEPT query returns all rows from the Orders table where Quantity is between 1 and 49, and those with a Quantity between 76 and 100. Worded another way; the query returns all rows where the Quantity is between 1 and 100, apart from rows where the quantity is between 50 and 75. SELECT * FROM Orders WHERE Quantity BETWEEN 1 AND 100 EXCEPT SELECT * FROM Orders WHERE Quantity BETWEEN 50 AND 75;
Example The following example is equivalent to the above example but without using the EXCEPT operator. SELECT o1.* FROM ( SELECT * FROM Orders WHERE Quantity BETWEEN 1 AND 100) o1 LEFT JOIN ( SELECT * FROM Orders WHERE Quantity BETWEEN 50 AND 75) o2 ON o1.id = o2.id WHERE o2.id IS NULL ==See also==