How can I get the set difference of two result sets?
Say I have a result set (just one column in each):
result1:
'a'
'b'
'c'
result2:
'b'
'c'
I want to minus what is in result1 by result2: result1 - result2 such that it equals:
difference of result1 - result2:
'a'
To perform result1 - result2, you can join result1 with result2, and only output items that exist in result1. For example:
Note that is not a set difference, and won't output items in result2 that don't exist in result1. It's set subtraction.
See also: http://www.bitbybit.dk/carsten/blog/?p=71
If you want things in
result1
that are not inresult2
, what about:Or:
NOTE: if
result1
is a subset ofresult2
then the above queries will return an empty set (they won't show you things inresult2
that are not inresult1
) so they are not set difference, but may be useful too (probably it's more efficient than the outer join).