How to Query NULL Value in MySql

How to query null values in MySql.

Misunderstanding NULL is common mistake beginners do while writing MySql query. While quering┬áin MySql they compare column name with NULL. In MySql NULL is nothing or in simple word it is Unknown Value so if you use comparison operator for NULL values you’ll get empty result.

Difference Between Inner Join and Left Join.

Let’s first create a table.

Related Post on MySql

Difference Between MyISAM and InnoDB Storage Engine

How to Increase PHPMyAdmin File Size Import Limit

Subscribe Our Tutorials

Get Latest Updates on Facebook

How to Query NULL Value in MySql

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

Second Mistake

NULL and ‘ ‘ (empty string) are different thing. NULL means value is unknown while empty string represents blank value.

This query will return empty result. In MySql, a 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 value in mysql, you have to use IS NULL.

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

For further reading on this topic

Compare Null Value in MySql


About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.