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,189
  • 11
  • 35
  • 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
  • 155,494
  • 24
  • 217
  • 209
1

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

Aaron Harun
  • 28,213
  • 8
  • 45
  • 61