tags:

views:

74

answers:

3

Possible Duplicate:
SQL NOT IN constraint and NULL values

Why is following query not returning hello?

select 'hello' where 'a' not in ('b', null)
A: 

I'm not sure about the lack of a table, but your list includes a NULL and so the SQL engine doesn't know whether or not 'a' is in the list.

jmoreno
+1  A: 

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

Aaron Harun
+3  A: 

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".

Adam Bernier
I think you meant: the first condition evaluates to TRUE, but the second doesn't, so the AND becomes FALSE.
egrunin
Thanks, @egrunin. Fixed.
Adam Bernier