0

i am have more than 100000 data in MySQL i have gender column some have female,male and null .i am writing query for showing all he data unfortunately it not showing the data which has null it only showing data with male and female below is my query can anyone tell where i went wrong thanks

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
Xavi
  • 2,552
  • 7
  • 40
  • 59

5 Answers5

2

change that

 OR `gender` = 'NULL'

to

OR `gender` is NULL

'NULL' is a string. AND NULL is NULL . have no length . (Null) .

echo_Me
  • 37,078
  • 5
  • 58
  • 78
0

Try with this:

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
prava
  • 3,916
  • 2
  • 24
  • 35
0

change that

 OR `gender` = 'NULL'

to

OR isnull(`gender`)
Samar Haider
  • 862
  • 10
  • 21
0

Here you have given

gender = 'female' OR gender = 'male' OR gender = '' OR gender = 'NULL'

Then why should you use as a condition

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
Dinesh G
  • 244
  • 1
  • 13
0

Change from

OR `gender` = 'NULL'

to

OR `gender` IS NULL

Check Manual for IS NULL.

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122