How to Select NULL Values in MySql

How to select null values in MySql. Misunderstanding NULL is a common mistake beginners do while writing a MySql query. While writing a query in MySql most of them compare column name with NULL. In MySql NULL is nothing or in simple word it is an Unknown Value so if you use comparison operator for NULL values you’ll get an empty result.

In this tutorial, We are going to learn how to write a query to select NULL values in MySql.

Difference Between Inner Join and Left Join

To understand this concept, let’s first create a table and insert some dummy values.

Related Post on MySql

Difference Between MyISAM and InnoDB Storage Engine

How to Increase PHPMyAdmin File Size Import Limit

How to Select NULL Values in MySql

How to Select Null Values in MySql

How to Select Null Values in MySql

Let’s see what happens when comparing emp_pan_card with NULL value.

Second Mistake

The NULL and ‘ ‘ (empty string) both are different. NULL means the value is unknown while an empty string represents a blank value.

This query will return an empty result. In MySql, NULL is never equal to anything, even another NULL.

** Never use arithmetic comparison operators such as =, <, or <> for NULL. If you use any arithmetic operator with NULL, the result is NULL.

To select rows which contain NULL values in a table, you have to use IS NULL condition.

To select rows where emp_pan_card column is not null we have to use IS NOT NULL condition.

For further reading on this topic

MySql documentation

Tagged , , . Bookmark the permalink.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.