Look at formal logic and algebra. Type expression
A & B & (D | E)
can be canceled in several ways:
The obvious way:
The above can also be counted, you just need to remember some properties of logical expressions:
!( A & B ) is the equivalent of (!A | !B) .!( A | B ) is the equivalent of (!A & !B) .!( !A ) is the equivalent of (A).
Distribute NOT (!) Throughout the expression to which it is applied, inverting operators and eliminating double negatives as you move:
So, in the general case, any where clause can be canceled in accordance with the above rules. Denial of this
select * from foo where test-1 and test-2 and ( test-3 OR test-4 )
is an
select * from foo where NOT( test-1 and test-2 and ( test-3 OR test-4 ) )
or
select * from foo where not test-1 OR not test-2 OR ( not test-3 and not test-4 )
What's better? This is a very context sensitive question. Only you can solve it.
Remember, however, that using NOT may affect what the optimizer may or may not do. You may receive a less optimal query plan.
Nicholas Carey May 27 '11 at 20:05 2011-05-27 20:05
source share