SQL IS NULL Practice: Finding Anonymous Web Sessions
A missing user_id is meaningful: it marks a visitor who was not signed in.
Not every visit is tied to a known person. When a visitor is not signed in, the session's user_id is NULL. Counting and inspecting those anonymous sessions is a routine analytics task.
Remember that NULL means "unknown", so it is never equal to anything. Writing user_id = NULL would match zero rows and give you a silently empty report.
IS NULL is the only reliable test
Use IS NULL to find missing values and IS NOT NULL to exclude them. This is the same rule you met with unreturned rentals and with the Garden Shop's empty shelves. It does not change just because the dataset does.
select columns
from table_name
where nullable_column is null
order by sort_columnSchema · Website AnalyticsTable · sessions7 columns · 30 rows
One row per visit. Anonymous visits have a null user_id; organic and direct visits have a null campaign_id.
List every anonymous session, meaning one with no user id. Return the session id, session date, channel, and device, oldest first.
- Columns: session_id, session_date, channel, device.
- Rows: 13 anonymous sessions.
- The earliest is session 14 on 2024-01-01 (direct, desktop).
Related
Find missing values with IS NULL.
Keep NULLs from silently changing filter results.
IS NULL, COALESCE, NULLIF, and null-safe logic.
IS NULL, COALESCE, NULLIF, and null-safe equality.