Understanding NULL Values in SQL: Functions
Module: Foundational Concepts
-- WRONG: WHERE column = NULL (returns 0 rows)
-- CORRECT: WHERE column IS NULL
-- NULL-safe calculation:
SELECT salary + COALESCE(bonus, 0) FROM employees;
-- Aggregates:
COUNT(*) includes NULLs, COUNT(column) excludes NULLs
NULL represents unknown, not empty or zero
Use IS NULL / IS NOT NULL for checks
NULL = NULL returns UNKNOWN, not TRUE
WHERE excludes UNKNOWN results
NULL propagates in calculations
Strict NULL handling, NULLS FIRST/LAST in ORDER BY
NULL sorts first in ASC, last in DESC
NULL sorts first by default
Core references in this topic include WHERE, =, != / <>. Learn what each one does, when to use it, and the execution or engine rules that matter.
WHERE
Filters rows before projection and sorting. It decides which rows continue through the query pipeline.
SELECT ... FROM table WHERE condition;
Most performance issues start with a weak WHERE clause or a missing supporting index.
=
Returns rows where the left and right values are exactly equal.
column = value
Use with exact matches. Do not use = NULL.
!= / <>
Returns rows where the compared values are not equal.
column <> value
SQL supports both <> and != in many engines, but <> is the portable form.
<, >, <=, >=
Range comparison operators for less-than, greater-than, and inclusive boundary checks.
salary >= 80000
OR
Matches rows when at least one condition is TRUE.
condition_a OR condition_b
Use parentheses when mixing OR with AND.
NOT
Negates a boolean condition and returns the opposite truth value.
NOT condition
IS NULL / IS NOT NULL
Tests whether a value is missing. SQL NULL semantics require dedicated NULL predicates.
manager_id IS NULL