MySQL - results from 'SELECT WHERE STH' and 'SELECT WHERE NOT STH' don't sum to full table
How is that possible that result开发者_StackOverflow中文版s from those 2 queries:
SELECT * FROM `workers` WHERE `name` = 'Smith`
and
SELECT * FROM `workers` WHERE NOT `name` = 'Smith`
doesn't sum to whole table workers?
Because NULL in name field does not get into either query.
In ternary logic which SQL uses, NULL = 'Smith' and NOT NULL = 'Smith' both evaluate to NULL and are filtered out.
Use NULL-safe comparison operator, <=>:
SELECT * FROM `workers` WHERE `name` <=> 'Smith`
and
SELECT * FROM `workers` WHERE NOT `name` <=> 'Smith`
加载中,请稍侯......
精彩评论