Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
No concept in relational databases trips up beginners and seasoned programmers more consistently than NULL. Because NULL represents missing or unknown information, standard equality operators (= and !=) do not work as expected. To inspect, filter, and handle missing values properly, you must use IS NULL and IS NOT NULL.
NULL? (And What It Isn't)Because NULL represents an unknown, nothing can equal NULL—not even another NULL!
IS NULL and IS NOT NULLBecause standard comparison operators fail on NULL, SQL provides dedicated unary operators:
WHERE column = NULLConsider this common junior developer error:
shipped_date = NULL.shipped_date contains '2026-03-10' or NULL, the expression evaluates to UNKNOWN!WHERE only returns rows that evaluate strictly to TRUE, this query will return ZERO rows 100% of the time!NULL in MySQLHow does ORDER BY handle rows with NULL values?
NULL values are treated as the lowest possible values.ORDER BY col ASC, rows containing NULL appear at the very beginning.ORDER BY col DESC, rows containing NULL appear at the very end.IFNULL() and COALESCE()When presenting query results to users or frontend applications, displaying raw NULL values looks unpolished. You can replace NULL with friendly fallback values:
IFNULL(expression, fallback_value) (MySQL Specific):COALESCE(val1, val2, ..., valN) (ANSI SQL Standard):Returns the first non-null value in its parameter list:
COUNT(col) vs `COUNT()`):**COUNT(*) counts all rows regardless of nullability.COUNT(column_name) counts only rows where that column is NOT NULL!SELECT * FROM employees WHERE bonus = NULL; return?NULL values when executing an ORDER BY column ASC statement?COUNT(*) and COUNT(commission_pct) on a table with 100 rows where 20 rows have NULL commissions?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Pattern Matching with LIKE & Wildcards | Sorting Data with ORDER BY |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.