MySQL IS NULL Operator
Introduction
To test whether a value is NULL or not, we use the IS NULL
operator.
Here is the basic syntax of the IS NULL
operator:
1
2
3
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
If the value is NULL, the expression returns true. Otherwise, it returns false.
To check if a value is not NULL, we use IS NOT NULL
operator:
1
2
3
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
Examples
The following query lists all customers with a NULL value in the “Address” field:
1
2
3
4
5
6
7
mysql> SELECT CustomerName, ContactName, Address FROM Customers
-> WHERE Address IS NULL;
+---------------------+--------------+---------+
| CustomerName | ContactName | Address |
+---------------------+--------------+---------+
| Alfreds Futterkiste | Maria Anders | NULL |
+---------------------+--------------+---------+