我在MySQL中有超过100000个数据,我有性别列,有些有女性,男性和null。我正在编写查询显示所有数据不幸的是,它没有显示有null的数据,它只显示男性和女性的数据下面是我的查询谁能告诉我哪里出错了,谢谢
SELECT DISTINCT contact.`id` , contact.`contactgroup` , contact.`media` , contact.`media2` , contact.`email1` , contact.`nationality` , contact.`country3` , contact.`twon` , contact.`area` , contact.`gender` , contact.`married` , contact.`children` , contact.`driverslicense`
FROM contact
WHERE isdeleted =0
AND (
`gender` = 'female'
OR `gender` = 'male'
OR `gender` = ''
OR `gender` = 'NULL'
)
LIMIT 180 , 30
改变
OR `gender` = 'NULL'
OR `gender` is NULL
'NULL'是一个字符串。AND NULL为NULL。没有长度。(空)。
试试这个:
SELECT DISTINCT contact.`id` , contact.`contactgroup` , contact.`media` ,
contact.`media2` , contact.`email1` , contact.`nationality` , contact.`country3` ,
contact.`twon` , contact.`area` , contact.`gender` , contact.`married` ,
contact.`children` , contact.`driverslicense`
FROM contact
WHERE isdeleted =0
AND (
`gender` = 'female'
OR `gender` = 'male'
OR `gender` = ''
OR `gender` IS NULL
)
LIMIT 180 , 30
改变
OR `gender` = 'NULL'
OR isnull(`gender`)
你给了
gender = 'female' OR gender = 'male' OR gender = '' OR gender = 'NULL'
那么为什么要用
作为条件呢?SELECT contact.id , contact.contactgroup , contact.media , contact.media2 , contact.email1 , contact.nationality , contact.country3 , contact.twon , contact.area , contact.gender , contact.married , contact.children , contact.driverslicense
FROM contact WHERE isdeleted =0 LIMIT 180 , 30
修改
OR `gender` = 'NULL'
OR `gender` IS NULL
手册检查 IS NULL
。