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    |	
+---------------------+--------------+---------+




Related Posts

MySQL INNER JOIN Clause

The INNER JOIN keyword selects records that have matching values...

MySQL Aliases

Aliases are nicknames. They give us a shorthand way of...

MySQL OR Operator

The OR operator combines two Boolean expressions and returns true...

MySQL LIMIT Operator

The LIMIT clause is used in the SELECT statement to...

MySQL LIKE Operator

The LIKE operator is used in a WHERE clause to...

MySQL IS NULL Operator

To test whether a value is NULL or not, we...