HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaModerate

Difference between "<> ANY(…)" and "NOT = ANY(…)"?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
anydifferencebetweenandnot

Problem

Could you please explain the difference between these two operators?

sID != smth and not sID = smth.

At a first glance they seem perfectly equal. But they give different results.

Solution

NOT sid = ANY (SELECT ...)


is equivalent to:

sid <> ALL (SELECT ...)


So, your two conditions are not the same.

ALL and ANY operators are hard for me (and many people) to use. I think that's how many prefer to use IN, NOT IN, EXISTS and NOT EXISTS which result in more self-explanatory code.

If you do want to work with them, think that sid = ANY (SELECT ...) means "check if sid is equal to any (some) of the (select...) values".

Then the NOT sid = ANY (SELECT ...) is the opposite of that. But the opposite of "equal to any of them" is "different to all of them" (and not "different to some of them").

Code Snippets

NOT sid = ANY (SELECT ...)
sid <> ALL (SELECT ...)

Context

StackExchange Database Administrators Q#143422, answer score: 10

Revisions (0)

No revisions yet.