Reputation: 2143
I get different results when i run select queries with != NULL
OR IS NOT NULL
.
/** No results returned.*/
SELECT *
FROM PORT_INFO
WHERE PORT_CODE != NULL;
/** Results are returned.*/
SELECT *
FROM PORT_INFO
WHERE PORT_CODE IS NOT NULL;
Upvotes: 2
Views: 108
Reputation: 1270021
Any comparison or operation with NULL
returns NULL
, with the exception of IS NULL
.
A NULL
boolean is considered to be false.
So, expressions like <> NULL
, = NULL
, and so on are always false.
This is ANSI standard behavior.
Upvotes: 0
Reputation: 30088
In SQL, there is no value that is equal to NULL, including NULL itself. To get what you expect, use IS NOT NULL.
Upvotes: 0
Reputation: 33993
From the documentation:
Because the result of any arithmetic comparison with NULL is also NULL, you cannot obtain any meaningful results from such comparisons.
So basically IS NOT NULL
will actually do what you intend, while !=
will do nothing useful (since it too will just return NULL
).
Upvotes: 2