The
EXCEPT
distinct Set Operator
The EXCEPT set operator logically first eliminates duplicate rows from the two input multisets—turn-
ing them to sets—and then returns only rows that appear in the first set but not the second. In other
words, a row is returned provided that it appears at least once in the first input multiset and zero
times in the second. Note that unlike the other two operators, EXCEPT is asymmetric; that is, with
the other set operators, it doesn’t matter which input query appears first and which second—with
EXCEPT, it does.
For example, the following code returns distinct locations that are employee locations but not
customer locations.
SELECT country, region, city FROM HR.Employees
EXCEPT
SELECT country, region, city FROM Sales.Customers;
This query returns the following two locations.
country region city
--------------- --------------- ---------------
USA WA Redmond
USA WA Tacoma
www.it-ebooks.info
Do'stlaringiz bilan baham: |