MySQL NULL Values

MySQL Tutorial

MySQL NULL Values

In MySQL, a NULL value represents missing, unknown, or undefined data. It is not the same as zero (0) or an empty string (”). NULL simply means no value has been stored.


Key Facts About NULL

Value TypeMeaning
NULLNo value / unknown
0Number zero (valid value)
'' (empty string)Text with zero characters
' ' (space)One character text

So:

  • NULL ≠ 0
  • NULL ≠ ''

 Example Table

idnameageemail
1Rahul25rahul@gmail.com
2PriyaNULLpriya@example.com
3Aman30NULL
  • Here, Priya’s age is unknown and Aman’s email is missing.

 Checking NULL Values (IS NULL)

To find rows where a column contains NULL:


 Checking Non-NULL Values (IS NOT NULL)


 Why Not Use = NULL?

This is incorrect:

Because NULL is not a value — it represents absence of a value — so equality comparison doesn’t work.


 Updating a Field to NULL


 Inserting NULL Values


 Using IFNULL() or COALESCE() to Handle NULL

Sometimes, you want to display a default value when NULL is found.


NULL in Comparisons with Operators

ExpressionResult
NULL = NULLFALSE
NULL <> NULLFALSE
NULL + 10NULL
COUNT(column)Ignores NULL values

 Summary

FeatureExample
Check for NULLIS NULL
Check for not NULLIS NOT NULL
Insert NULLVALUES (NULL)
Update to NULLSET column = NULL
Display alternate valueIFNULL() or COALESCE()

 NULL values help represent missing information in the database.

You may also like...