Lesson Description
NULL is "unknown" — comparisons need IS NULL.
Lesson 3 of 4
Progress: 0/3 exercises solved (0%)
Solve all exercises below to unlock the next lesson.
Lesson Description
NULL is "unknown" — comparisons need IS NULL.
Easy Project
Mini project: Turn this lesson into a real-world query artifact by writing one clean business report query and validating output quality.
NULL means unknown or missing — it is not zero, not an empty string, and not false.
Comparing anything to NULL with = or != always yields NULL (not TRUE or FALSE):
-- This returns NO rows, even if manager_id is NULL
WHERE manager_id = NULL -- WRONG
-- This is correct
WHERE manager_id IS NULL
-- Employees with no manager assigned
SELECT first_name, last_name
FROM employees
WHERE manager_id IS NULL;
-- Employees who have a manager
SELECT first_name, last_name
FROM employees
WHERE manager_id IS NOT NULL;
COALESCE(a, b, c, ...) returns the first non-NULL argument:
SELECT
first_name,
COALESCE(manager_id::text, 'No manager') AS manager
FROM employees;
Most aggregate functions (SUM, AVG, COUNT(col)) silently skip NULLs. COUNT(*) counts all rows including those with NULLs.
IS NULL to detect unmatched rows (covered in Joins).NULLIF(a, b) returns NULL when a = b — useful to avoid divide-by-zero: salary / NULLIF(hours, 0).This lesson is part of Filtering & Logic. Focus on the core idea in Working with NULL, then validate with deliberate practice.
What to master
Common mistakes
High-level strategy
Task ladder
Transparent data checks
Retention loop
Logical reasoning for commands
WHERE
Why: Limits rows to only the business-relevant subset.
Memory cue: Filter early to reduce noise.
ORDER BY
Why: Makes output deterministic and reviewable.
Memory cue: No ORDER BY means no guaranteed row order.
AS alias
Why: Makes output columns readable for teams and reports.
Memory cue: If the name is clear, the query is easier to trust.
Concept check
3 quick questions. One at a time. Instant score at the end.
Return first_name and last_name of HR employees who have NO manager (manager_id is NULL).
From the hospital sandbox, return first_name and last_name of patients whose gender is recorded (not NULL).
Return first_name and last_name of employees who have both a manager_id and a department_id (neither is NULL). Order by last_name.
Lesson 3 of 4
0/3 solved (0%)
Finish this lesson to unlock next.