Skip to content
/ Chapter 13 · Applied Practice: Website Analytics
Lesson 13.4 · website_analytics
Lesson 13.4

SQL IS NULL Practice: Finding Anonymous Web Sessions

In this dataset, a missing user_id represents a session that wasn't tied to a signed-in user.

Not every visit is tied to a known person. In this dataset, sessions that aren't tied to a signed-in user have a missing user_id, represented as NULL. Counting and inspecting those anonymous sessions is a routine analytics task.

Remember that NULL is a missing/unknown marker, so ordinary equality comparisons with it aren't true. Writing user_id = NULL would match zero rows and give you an empty report with no error.

Test missing values with IS NULL

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 unshipped orders. It doesn't change just because the dataset does.

Pattern
select columns
from table_name
where nullable_column is null
order by sort_column
Schema · Website Analytics Table · sessions 7 columns · 30 rows
Table · sessions

One row per visit. Anonymous visits have a null user_id; organic and direct visits have a null campaign_id.

7 columns · 30 rows
session_id int user_id int session_date date channel text campaign_id int device text duration_seconds int
Your task

List every anonymous session, meaning one with no user id. Return the session id, session date, channel, and device, oldest first.

·

Run your query to inspect the result.

Expected answer
  • Columns: session_id, session_date, channel, device.
  • Rows: 13 anonymous sessions.
  • The earliest is session 14 on 2024-01-01 (direct, desktop).