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
0

5 Answers 5

2

change that

 OR `gender` = 'NULL'

to

OR `gender` is NULL

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

change that

 OR `gender` = 'NULL'

to

OR isnull(`gender`)

Comments

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

Comments

0

Change from

OR `gender` = 'NULL'

to

OR `gender` IS NULL

Check Manual for IS NULL.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.