2

Possible Duplicate:
SQL NOT IN constraint and NULL values

Why is following query not returning hello?

select 'hello' where 'a' not in ('b', null)
Community
  • 1
  • 1
Novice Developer
  • 4,489
  • 11
  • 39
  • 42

2 Answers2

3

Your query can be expanded to:

SELECT 'hello' WHERE 'a' <> 'b' AND 'a' <> NULL;

The first condition evaluates to true.

The second condition evaluates to neither true nor false because NULL is neither equal nor unequal to anything. The full WHERE clause is then: "true AND neither true nor false".

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
  • I think you meant: the first condition evaluates to TRUE, but the second doesn't, so the AND becomes FALSE. – egrunin Jun 25 '10 at 08:26
1

The short answer is you can't have a null value.

Aaron Butacov
  • 32,415
  • 8
  • 47
  • 61