Reputation: 6232
I have a table with device
column which could be 'P', 'T' or NULL, but the condition like device NOT IN('P', 'T')
seems to miss the rows with NULL. Can be demonstrated with following queries
$ bq query 'SELECT count(*) FROM t'
+----------+
| f0_ |
+----------+
| 29542063 |
+----------+
$ bq query "SELECT count(*) FROM t WHERE device = 'P' OR device = 'T'"
+---------+
| f0_ |
+---------+
| 8268436 |
+---------+
$ bq query "SELECT count(*) FROM t WHERE NOT (device = 'P' OR device = 'T')"
+-----+
| f0_ |
+-----+
| 0 |
+-----+
$ bq query "SELECT count(*) FROM t WHERE device IS NULL"
+----------+
| f0_ |
+----------+
| 21273627 |
+----------+
Why the query with WHERE NOT
returns 0
while IS NULL
one returns correct result?
Upvotes: 1
Views: 220
Reputation: 59165
"Why the query with WHERE NOT returns 0 while IS NULL one returns correct result?"
Because
SELECT null != 'anything'
returns 'null', not 'false'.
Upvotes: 3