Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to check for NULL value in MySql query

Tags:

mysql

Can any one please let me know the best way to use IF statement in mysql query to show if the "email" field is NULL then it should show as "no email"...

Postcode    Telephone             Email
----------------------------------------------------------
BS20 0QN    1275373088         no email
BS20 0QN    1275373088         no email
PO9 4HG 023 92474208        [email protected]
SO43 7DS    07801 715200       [email protected]
----------------------------------------------------------
like image 550
Prabhu M Avatar asked May 16 '10 12:05

Prabhu M


People also ask

How do I check if a variable is NULL in MySQL?

The MySQL ISNULL() function is used for checking whether an expression is NULL or not. This function returns 1 if the expression passed is NULL, else it returns 0.

How do I check if a field is empty in MySQL?

The IS NULL operator is used to test for empty values (NULL values).

How do you find the NULL value of data?

Checking for missing values using isnull() In order to check null values in Pandas DataFrame, we use isnull() function this function return dataframe of Boolean values which are True for NaN values.


2 Answers

Use the COALESCE function:

COALESCE(Email, 'no email')
like image 162
Marcelo Cantos Avatar answered Sep 30 '22 18:09

Marcelo Cantos


Try this way

SELECT * 
FROM table 
WHERE YourColumn IS NULL;
like image 24
lasantha Avatar answered Sep 30 '22 17:09

lasantha