SQL Practice Logo

SQLPractice Online

NULL-Safe Filtering: Interview

Module: Advanced Filtering

Why does WHERE column = NULL not work?

NULL comparisons with = return NULL (not true or false). NULL is unknown, so NULL = NULL is unknown. Use IS NULL to explicitly test for NULL values.

How do you handle optional filter parameters that might be NULL?

Use OR with IS NULL: WHERE (column = value OR column IS NULL). Or use COALESCE: WHERE COALESCE(column, default) = value. Choose based on business logic.

Find customers without phone numbers

SELECT * FROM customers WHERE phone IS NULL;

IS NULL correctly identifies NULL values. = NULL would not work.