Question

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?

Était-ce utile?

La solution

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.

Autres conseils

you can do this to be sure.

 SELECT table.field FROM table WHERE table.field > 0
                               AND table.field is not null
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top