Вопрос

I use query like this:
SELECT table.field FROM table WHERE table.field > 0
Would WHERE clause be working if table.field contain NULL value?

Это было полезно?

Решение

The where clause will work the way it is supposed to. Just about all comparisons to NULL return NULL, which is treated as "false" in the where clause.

So, all these expressions will return no rows if the value is NULL:

WHERE table.field > 0
WHERE table.field = 0
WHERE table.field < 0
WHERE table.field <> 0

If you are concerned about NULL values, test for them explicitly (using is null or is not null) or use a function like coalesce() to give the field a value when it is NULL.

Другие советы

you can do this to be sure.

 SELECT table.field FROM table WHERE table.field > 0
                               AND table.field is not null
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top