Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

I've written a query to check for users with certain criteria, one being they have an email address.

Our site will allow a user to have or not have an email address.


 SELECT `userID` 

 FROM `users` 

 WHERE `userID` 


         FROM `users_indvSettings`

  WHERE `indvSettingID`=5 AND `optionID`='.$time.')

  AND `email`!=""


Is this the best way to check for an empty field in SQL? I've just tried "IS NOT NULL" and this still returned a user's record without them having an email address.

The query above works but out of curiosity, I wondered if I'm doing it the correct way.

1 Answer

0 votes
by (40.7k points)

To handle both of them, try this:

email > ''

The above code will benefit you from the range access if you have lots of empty email records (both types) in your table.

Note: An empty field can be either an empty string or a NULL.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 31, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Oct 7, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 18, 2019 in SQL by Tech4ever (20.3k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers


108k users

Browse Categories