SQL Query

MySQL: How to Filter NULL Values in SQL

MySQL guide: Handle NULL values using IS NULL, IS NOT NULL, and COALESCE.

This guide is specifically for MySQL syntax.

How to Filter NULL Values in SQL

Handle NULL values using IS NULL, IS NOT NULL, and COALESCE.

Quick Answer

SELECT * FROM table WHERE column IS NULL;

Explanation

NULL represents unknown/missing data. Use IS NULL/IS NOT NULL for comparison (= NULL doesn't work). COALESCE returns the first non-NULL value.

Query Variants

Is Null

SELECT * FROM employees WHERE manager_id IS NULL;

Is Not Null

SELECT * FROM employees WHERE phone IS NOT NULL;

Coalesce

SELECT name, COALESCE(phone, 'No phone') as phone FROM employees;

Nullif

SELECT name, NULLIF(status, 'inactive') as active_status FROM users;

Pro Tips

  • Never use = NULL, always use IS NULL
  • COALESCE handles multiple fallback values
  • NULL in calculations returns NULL

Related SQL Queries

Continue learning with more SQL query examples:


MySQL-Specific Notes

This page covers MySQL syntax. Other databases may have different syntax for similar operations.

Related Content

From Our Blog

Try it yourself

Practice this query in our interactive SQL sandbox.