Non-Bot Acknowledged Alerts

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
TransUnion

Problem

During on-call incident review, pull all alerts that were not acknowledged by 'alice', including alerts that were never acknowledged at all. Show all fields, and walk the incident timeline from the earliest alert that fired through to the most recent.

Human-acknowledged alerts only.

Tables

alert_events

Columns: alert_id INTEGER, svc_name TEXT, severity TEXT, status TEXT, fired_at TIMESTAMP, ack_by TEXT, resolved TIMESTAMP

alert_events: 10 of 200 rows
alert_idsvc_nameseveritystatusfired_atack_byresolved
129payment-apihighacknowledged2026-02-02 01:07:00bob2026-02-02 03:11:00
158user-svcmediumresolved2026-03-03 02:14:00charlie2026-03-03 04:22:00
187search-apilowsilenced2026-04-04 03:21:00danaNULL
216gatewayCriticalfiring2026-05-05 04:28:00NULL2026-05-05 06:44:00
245notif-svcHIGHacknowledged2026-06-06 05:35:00alice2026-06-06 07:55:00
274db-primarycriticalresolved2026-07-07 06:42:00bobNULL
303cache-01highsilenced2026-08-08 07:49:00charlie2026-08-08 09:17:00
332auth-svcmediumfiring2026-09-09 08:56:00NULL2026-09-09 10:28:00
361payment-apilowacknowledged2026-01-10 09:03:00eveNULL
390user-svcCriticalresolved2026-02-11 10:10:00alice2026-02-11 12:50:00

Expected output

First 5 of 170 rows
alert_idsvc_nameseveritystatusfired_atack_byresolved
10003001payment-apihighacknowledged2022-01-02 01:07:00bob2022-01-02 03:11:00
10003061notif-svchighacknowledged2022-01-06 13:07:00bob2022-01-06 15:11:00
10003026user-svcmediumresolved2022-02-03 02:02:00bob2022-02-03 04:46:00
10003051search-apilowsilenced2022-03-24 03:57:00bobNULL
10003016auth-svcCriticalfiring2022-04-17 16:52:00NULL2022-04-17 18:56:00

Worked solution and explanation

What this really tests

This looks like a one-line filter on alert_events, but it is three-valued logic wearing an on-call costume. A not-equal comparison against NULL is neither true nor false, and WHERE keeps only rows that come out true. Most candidates write WHERE ack_by != 'alice' and move on. That silently drops every alert nobody ever acknowledged, 50 of the 200 rows here, so the result comes back with 120 rows instead of 170. Those are the alerts an on-call review most needs to see, and the prompt asks for them by name.


Break down the requirements

Step 1: Apply the NOT-alice filter with NULL awareness

For a row whose ack_by is NULL, ack_by != 'alice' evaluates to NULL, and WHERE drops it. The OR ack_by IS NULL branch is true for exactly those rows, so they come back in while alice's rows stay out.

Step 2: Order by fired_at

ORDER BY fired_at is ascending by default, which walks the timeline from earliest to latest. fired_at is stored as text in 'YYYY-MM-DD HH:MM:SS' form, so string order is chronological order here, and the column has no nulls to place.

Step 3: Return all fields

SELECT * returns all 7 columns in table order: the full alert record the review asked for.


The solution

The version that loses the unacknowledged alerts
SELECT *
FROM alert_events
WHERE ack_by != 'alice'
ORDER BY fired_at

Every row with ack_by null evaluates to NULL in the filter and is dropped, so the result comes back short of 170 rows.

`NULL`-aware inequality filter
SELECT *
FROM alert_events
WHERE ack_by != 'alice' OR ack_by IS NULL
ORDER BY fired_at

The OR ack_by IS NULL branch is the whole answer: it readmits the alerts nobody acknowledged.

Bare inequality
WHERE ack_by != 'alice' keeps 'bob', 'eve' and the rest. The auth-svc 'firing' alert with ack_by null evaluates to NULL and disappears without any error.
NULL-aware
WHERE ack_by != 'alice' OR ack_by IS NULL keeps the same named acknowledgers plus every never-acknowledged alert, which brings the result to the full 170 rows.

Common follow-up questions