Best way to check for NULL in a MySql query

Can someone please let me know how best to use the IF statement in mysql query to show that the "email" field is NULL, then it should display as "no email" ...

Postcode    Telephone             Email
----------------------------------------------------------
BS20 0QN    1275373088         no email
BS20 0QN    1275373088         no email
PO9 4HG 023 92474208        prabhu1@vacmedia.com
SO43 7DS    07801 715200       test@vacmedia.com
----------------------------------------------------------
+3
source share
3 answers

Use the COALESCE function:

COALESCE(Email, 'no email')
+9
source

Try this way

SELECT * 
FROM table 
WHERE YourColumn IS NULL;
+4
source

Try IFNULLfunction :

SELECT Postcode, Telephone, IFNULL(Email, "no email")
FROM table
+3
source

Source: https://habr.com/ru/post/1745636/


All Articles