Working with NULL Values

SQL NULL Handling – IS NULL vs = NULL

Why = NULL doesn’t work in SQL

By Sharanmeet Singh
Tags:SQLNULLIS NULLCOALESCE

SQL Query Generator

Generate SQL queries for database operations

Try Generator

SQL NULL Handling

NULL in SQL represents missing or unknown values.


Common Mistake

SELECT * FROM employees WHERE manager_id = NULL;

This doesn’t return any rows.


Correct Way

SELECT * FROM employees WHERE manager_id IS NULL;

Finds employees with no manager.


IS NOT NULL Example

SELECT * FROM employees WHERE manager_id IS NOT NULL;

Why?

  • NULL is not equal to anything, not even itself
  • Always use IS NULL or IS NOT NULL

Tip: Use COALESCE() or IFNULL() to handle NULLs in calculations.