2014-07-03 257 views
0

我在MySQL中有超過100000個數據我有性別列一些有女性,男性和空。我正在寫查詢顯示所有他的數據,不幸的是它沒有顯示數據只有null顯示男性和女性在下面的數據我的查詢誰能告訴我哪裏錯了感謝mysql查詢不顯示空值

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 

回答

2

變化是

OR `gender` = 'NULL' 

OR `gender` is NULL 

'NULL'是一個字符串。 AND NULL爲NULL。沒有長度。 (空值) 。

0

嘗試這樣的:

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 
0

變化是

OR `gender` = 'NULL' 

OR isnull(`gender`) 
0

在這裏,你已經給

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 
0

更改使用來自

OR `gender` = 'NULL' 

OR `gender` IS NULL 

檢查ManualIS NULL